From: Peter Palfrader Date: Thu, 18 Sep 2008 20:53:17 +0000 (+0200) Subject: Command parsing X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb0437f53277543cfd66c388b20cc15c2ad3a50f;p=pwstore Command parsing --- diff --git a/pws b/pws index 7cc1529..742007a 100755 --- a/pws +++ b/pws @@ -480,13 +480,35 @@ class Ed end end -case ARGV.shift - when 'ls': Ls.new - when 'ed': Ed.new - else - STDERR.puts "What!?" + +def help(code=0, io=STDOUT) + io.puts "Usage: #{$program_name} ed" + io.puts " #{$program_name} ls" + io.puts " #{$program_name} help" + io.puts "Call #{$program_name} --help for additional options/parameters" + exit(code) end + +def parse_command + case ARGV.shift + when 'ls': Ls.new + when 'ed': Ed.new + when 'help': + case ARGV.length + when 0: help + when 1: + ARGV.push "--help" + parse_command + else help(1, STDERR) + end + else + help(1, STDERR) + end +end + +parse_command + # vim:set shiftwidth=2: # vim:set et: # vim:set ts=2: