summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2013-01-08 11:48:31 +0000
committerLee Jarvis <ljjarvis@gmail.com>2013-01-08 11:48:31 +0000
commit55a1ee79f603d89a76bc5dac7a5c75e97ed2d17c (patch)
treec12f038aabee0ec012ab2abe660ee26d9361a479 /README.md
parent93ec4d29629be94747d98e924369bc4e49606aea (diff)
downloadslop-55a1ee79f603d89a76bc5dac7a5c75e97ed2d17c.tar.gz
updated readme with command example
Diffstat (limited to 'README.md')
-rw-r--r--README.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/README.md b/README.md
index 3f3972f..0943a6d 100644
--- a/README.md
+++ b/README.md
@@ -110,6 +110,32 @@ opts.to_hash #=> {:foo=>"bar", :baz=>true, :name=>"lee"}
opts.fetch_option(:name).expects_argument? #=> true
```
+Commands
+--------
+
+Slop supports git style sub-commands, like so:
+
+```ruby
+opts = Slop.parse do
+ on '-v', 'Print the version' do
+ puts "Version 1.0"
+ end
+
+ command 'add' do
+ on :v, :verbose, 'Enable verbose more'
+
+ run do |opts, args|
+ puts "You ran 'add' with options #{opts.to_hash} and args: #{args.inspect}"
+ end
+ end
+end
+
+# ruby run.rb -v
+#=> Version 1.0
+# ruby add -v foo
+#=> You ran 'add' with options {:verbose=>true} and args ["foo"]
+```
+
Woah woah, why you hating on OptionParser?
------------------------------------------