summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md25
-rw-r--r--lib/slop/types.rb2
2 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index 29bddef..747c402 100644
--- a/README.md
+++ b/README.md
@@ -33,8 +33,29 @@ opts.to_hash #=> { host: "192.168.0.1", port: 80, verbose: true, quiet: false }
Advanced Usage
--------------
-Printing Help
--------------
+This example is really just to describe how the underlying API works.
+It's not necessarily the best way to do it.
+
+```ruby
+opts = Slop::Options.new
+opts.banner = "usage: connect [options] ..."
+opts.separator ""
+opts.separator "Connection options:"
+opts.string "-H", "--hostname", "a hostname"
+opts.int "-p", "--port", "a port", default: 80
+opts.separator ""
+opts.separator "Extra options:"
+opts.array "--files", "a list of files to import"
+opts.bool "-v", "--verbose", "enable verbose mode"
+
+parser = Slop::Parser.new(opts)
+result = parser.parse(["--hostname", "192.168.0.1"])
+
+result.to_hash #=> { hostname: "192.168.0.1", port: 80,
+ # files: [], verbose: false }
+
+puts opts # prints out help
+```
Arrays
------
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index b89da60..1ebc465 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -18,12 +18,14 @@ module Slop
false
end
end
+ BooleanOption = BoolOption
class IntegerOption < Option
def call(value)
value =~ /\A\d+\z/ && value.to_i
end
end
+ IntOption = IntegerOption
class ArrayOption < Option
def call(value)