]> err.no Git - pwstore/commitdiff
Command parsing
authorPeter Palfrader <peter@palfrader.org>
Thu, 18 Sep 2008 20:53:17 +0000 (22:53 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 18 Sep 2008 20:53:17 +0000 (22:53 +0200)
pws

diff --git a/pws b/pws
index 7cc1529bfd0b0c7aa013948a7dcaa7723f43119f..742007a3d822ae0b3188648d12608005580e87a0 100755 (executable)
--- 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} <command> --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: