summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorLee Jarvis <lee@jarvis.co>2011-04-14 20:38:19 +0100
committerLee Jarvis <lee@jarvis.co>2011-04-14 20:38:19 +0100
commit22c55c35ba5ad49156175a5be7120dcaaac38c63 (patch)
treeb7bf0f85a876c1222b714271a1c6e8e810faac66 /README.md
parent774b3136d1704de2a27397e3c13810a4d8693a08 (diff)
downloadslop-22c55c35ba5ad49156175a5be7120dcaaac38c63.tar.gz
added commands example to readme
Diffstat (limited to 'README.md')
-rw-r--r--README.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/README.md b/README.md
index da253a8..1c5fc04 100644
--- a/README.md
+++ b/README.md
@@ -315,6 +315,41 @@ yields:
-n, --name Your name
-h, --help Print this help message
+Commands
+--------
+
+Slop allows you to nest more instances of Slop inside of `commands`. These
+instances will then be used to parse arguments if they're called upon.
+
+Slop will use the first argument in the list of items passed to `parse` to
+check if it is a `command`.
+
+ Slop.parse ['foo', '--bar', 'baz']
+
+Slop will look to see if the `foo` command exists, and if it does, it'll pass
+the options ['--bar', 'baz'] to the instance of Slop that belongs to `foo`.
+Here's how commands might look:
+
+ opts = Slop.new do
+ command :foo do
+ on :b, :bar, 'something', true
+ end
+
+ command :clean do
+ on :v, :verbose, do
+ puts 'Enabled verbose mode for clean'
+ end
+ end
+
+ # non-command specific options
+ on :v, :version do
+ puts 'version 1'
+ end
+ end
+
+Now with `run.rb -v` this will print `version 1` and with
+`run.rb clean -v` it will print `Enabled verbose mode for clean`
+
Woah woah, why you hating on OptionParser?
------------------------------------------