aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-03-17 02:19:53 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-03-17 02:19:53 +0100
commit285f6aa6eafba2e9e491646641c04cc06629c387 (patch)
tree0abf480cb6aa41aee5e2a66b2aff01d888e2c280
parente9d6911ac3a87a087746d04d850c64f2f6efa9b8 (diff)
Add a --help/-? option.
-rwxr-xr-xicevault25
1 files changed, 11 insertions, 14 deletions
diff --git a/icevault b/icevault
index 71ecfb8..3ec9acb 100755
--- a/icevault
+++ b/icevault
@@ -21,7 +21,7 @@ use warnings;
our $VERSION = '0.1';
use Getopt::Long qw/:config posix_default no_ignore_case gnu_compat
- bundling auto_help auto_version/;
+ bundling auto_version/;
use Digest ();
use Encode qw/decode_utf8 encode_utf8/;
use File::Copy 'move';
@@ -77,10 +77,11 @@ sub warning($@) {
# Print usage and exit.
sub usage($) {
my $rv = shift;
- print STDERR "Usage: $0 [OPTIONS] [fill] scheme://hostname/identity\n"
- ." or: $0 [OPTIONS] insert [identity]\n"
- ." or: $0 [OPTIONS] dump identity\n";
- myprintf \*STDERR, 'Try C<%s> for more information.', "$0 --help";
+ my $fh = $rv ? \*STDERR : \*STDOUT;
+ print $fh "Usage: $0 [OPTIONS] [fill] scheme://hostname/identity\n"
+ ." or: $0 [OPTIONS] insert [identity]\n"
+ ." or: $0 [OPTIONS] dump scheme://hostname/identity\n"
+ . "Consult the manual page for more information.\n";
exit $rv;
}
@@ -138,12 +139,8 @@ sub loadConfig($) {
chomp;
s/#.*//; # ignore comments
next if /^\s*$/; # ignore empty and blank lines
- /^([-\@\w.]+)(?:\s*=\s*)(\p{print}*)/ or error "Can't parse config line: C<%s>", $_;
- if ($2 eq '') {
- delete $CONFIG{$1};
- } else {
- $CONFIG{$1} = $2;
- }
+ /^([-\@\w.]+)(?:\s*=\s*)(\p{print}+)/ or error "Can't parse config line: C<%s>", $_;
+ $CONFIG{$1} //= $2;
}
close $CONFIG;
}
@@ -435,14 +432,14 @@ sub sha256_file($) {
#######################################################################
+GetOptions(\%CONFIG, qw/debug show-passwords|p socket|s=s help|?/) or usage(1);
+usage(0) if $CONFIG{help};
+
# Load configuration
my $XDG_CONFIG_HOME = $ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config";
my $XDG_DATA_HOME = $ENV{XDG_DATA_HOME} // "$ENV{HOME}/.data";
loadConfig "$XDG_CONFIG_HOME/icevault";
-# Override options from command line
-GetOptions(\%CONFIG, qw/debug show-passwords|p socket|s=s/) or usage(1);
-
# Default options
$CONFIG{gpg} //= 'gpg';
$CONFIG{socket} //= 'S.IceVault';