From 285f6aa6eafba2e9e491646641c04cc06629c387 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 17 Mar 2015 02:19:53 +0100 Subject: Add a --help/-? option. --- icevault | 25 +++++++++++-------------- 1 file 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'; -- cgit v1.2.3