summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-04-18 02:58:39 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2009-04-18 02:58:39 +0200
commitc2a39445602c18ea44eaaea53156190b3d47c3e1 (patch)
tree5ca76e9887d18fa03859c95e453c1a187ca1aa9e
parent16daa13db548e87e25806c2036fe5acb0276a05e (diff)
envstore: Improved error messages, show usage whenever getting bad input
-rwxr-xr-xbin/envstore19
1 files changed, 14 insertions, 5 deletions
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 <eval|show|clear>\n";
+ print STDERR " envstore save <var> [value]\n";
+ print STDERR " envstore rm <var>\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 <save|eval|show|rm|clear> [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<save> I<variable>[=I<value>]
+=item B<save> I<variable> [I<value>]
Save I<variable> either with it's current shell value or with I<value>