diff options
-rwxr-xr-x | icevault | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -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'; |