Created
March 16, 2011 17:41
-
-
Save leejarvis/872910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'slop' | |
opts = Slop.parse do | |
banner "Usage: ruby foo.rb [options]\n" | |
on :n, :name, 'Your username', true | |
on :a, :age, 'Your age (optional)', :optional => true | |
on :V, :verbose, 'Run in verbose mode', :default => false | |
on :P, :people, 'Some people', true, :as => Array | |
on :h, :help, 'Print this help screen' do | |
puts help | |
end | |
end | |
# ruby foo.rb --name 'Lee Jarvis' -V --people john,phillip,dan | |
p opts.name? #=> true | |
p opts[:name] #=> "Lee Jarvis" | |
p opts.age? #=> false | |
p opts[:age] #=> nil | |
p opts.verbose? #=> true | |
p opts[:people] #=> ["john", "phillip", "dan"] | |
# grab an Option object | |
p opts.options[:people].description #=> "Some people" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment