diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-07-09 22:02:54 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-07-09 22:02:54 +0200 |
commit | 622a4ad3f3e7da1837f253f816788069631891ad (patch) | |
tree | 83b0b5cd616528e767cb639243b5b0ea2a9ab4d0 /bin/raps2 | |
parent | d15919da44f5fa458a759f251c07677953d12b77 (diff) |
raps2: Usability improvements, argument validation
Diffstat (limited to 'bin/raps2')
-rwxr-xr-x | bin/raps2 | 56 |
1 files changed, 47 insertions, 9 deletions
@@ -40,6 +40,10 @@ sub file_must_not_exist { sub cmd_add { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'add <account>' ); + } + my $pwfile = data_home('raps2') . "/${name}"; file_must_not_exist( $pwfile, $name ); @@ -65,6 +69,10 @@ sub cmd_add { sub cmd_dump { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'dump <account>' ); + } + my $pwfile = data_files("raps2/${name}"); file_must_exist( $pwfile, $name ); @@ -88,6 +96,10 @@ sub cmd_dump { sub cmd_edit { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'edit <account>' ); + } + my $pwfile = data_files("raps2/${name}"); file_must_exist( $pwfile, $name ); @@ -122,6 +134,10 @@ sub cmd_edit { sub cmd_get { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'get <account>' ); + } + my $pwfile = data_files("raps2/${name}"); file_must_exist( $pwfile, $name ); @@ -139,9 +155,24 @@ sub cmd_get { return; } +sub cmd_help { + my ( $exit_status, $subcmd ) = @_; + + $subcmd //= 'add|get|dump|... [account]'; + + say "Usage: raps2 ${subcmd}"; + say 'See also: "man raps2"'; + + exit $exit_status; +} + sub cmd_info { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'info <account>' ); + } + my $pwfile = data_files("raps2/${name}"); file_must_exist( $pwfile, $name ); @@ -170,6 +201,10 @@ sub cmd_list { sub cmd_remove { my ($name) = @_; + if ( not $name ) { + cmd_help( 1, 'del <account>' ); + } + my $pwfile = data_files("raps2/${name}"); file_must_exist( $pwfile, $name ); @@ -181,15 +216,18 @@ sub cmd_remove { } given ($action) { - when ('add') { cmd_add(@args) } - when ('del') { cmd_remove(@args) } - when ('dump') { cmd_dump(@args) } - when ('edit') { cmd_edit(@args) } - when ('get') { cmd_get(@args) } - when ('info') { cmd_info(@args) } - when ('list') { cmd_list(@args) } - when ('version') { say "raps2 version ${VERSION}" } - default { die "Unknown action: ${action}\n" } + when ('add') { cmd_add(@args) } + when ('del') { cmd_remove(@args) } + when ('dump') { cmd_dump(@args) } + when ('edit') { cmd_edit(@args) } + when ('get') { cmd_get(@args) } + when ('info') { cmd_info(@args) } + when ('list') { cmd_list(@args) } + + when ( [qw[version -v --version]] ) { say "raps2 version ${VERSION}" } + when ( [qw[help -h --help ]] ) { cmd_help(0) } + + default { cmd_help(1) } } __END__ |