From c2a39445602c18ea44eaaea53156190b3d47c3e1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 Apr 2009 02:58:39 +0200 Subject: envstore: Improved error messages, show usage whenever getting bad input --- bin/envstore | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/envstore b/bin/envstore index 5dad484..f16aba8 100755 --- a/bin/envstore +++ b/bin/envstore @@ -12,6 +12,13 @@ my $arg = shift; my $arg2 = shift; my ($key, $value); +sub usage { + print STDERR "Usage: envstore \n"; + print STDERR " envstore save [value]\n"; + print STDERR " envstore rm \n"; + exit(1); +} + sub check_store { my ($mode, $uid); unless (-e $store_file) { @@ -60,15 +67,17 @@ sub get_keyvalue { if (exists($ENV{$key})) { $value = $ENV{$key}; } else { - print STDERR "No such parameter: $key"; + print STDERR "No such parameter: $key\n"; exit(1); } } return($key, $value); } +usage unless defined($action); load_store; if ($action eq 'save') { + usage unless defined($arg); ($key, $value) = get_keyvalue($arg, $arg2); $store{$key} = $value; save_store; @@ -77,18 +86,18 @@ if ($action eq 'save') { $value =~ s/'/'"'"'/g; print "export $key='$value'\n"; } -} elsif ($action eq 'show') { +} elsif ($action eq 'show' or $action eq 'list') { while (($key, $value) = each(%store)) { printf("%-15s = %s\n", $key, $value); } } elsif ($action eq 'rm') { + usage unless defined($arg); delete($store{$arg}); save_store; } elsif ($action eq 'clear') { unlink($store_file); } else { - print STDERR "Usage: envstore [args]\n"; - exit(1); + usage; } __END__ @@ -117,7 +126,7 @@ Forget all stored variables Produce shell code for evaluation, restoring all saved variables -=item B I[=I] +=item B I [I] Save I either with it's current shell value or with I -- cgit v1.2.3