Class | Slop |
In: |
lib/slop/commands.rb
lib/slop/option.rb lib/slop.rb |
Parent: | Object |
VERSION | = | '3.3.2' | ||
DEFAULT_OPTIONS | = | { :strict => false, :help => false, :banner => nil, :ignore_case => false, :autocreate => false, :arguments => false, :optional_arguments => false, :multiple_switches => true, :longest_flag => 0 | Returns a default Hash of configuration options this Slop instance uses. |
config | [R] | The Hash of configuration options for this Slop instance. |
options | [R] | The Array of Slop::Option objects tied to this Slop instance. |
Build a Slop object from a option specification.
This allows you to design your options via a simple String rather than programatically. Do note though that with this method, you‘re unable to pass any advanced options to the on() method when creating options.
string - The optspec String config - A Hash of configuration options to pass to Slop.new
Examples:
opts = Slop.optspec(<<-SPEC) ruby foo.rb [options] --- n,name= Your name a,age= Your age A,auth Sign in with auth p,passcode= Your secret pass code SPEC opts.fetch_option(:name).description #=> "Your name"
items - The Array of items to extract options from (default: ARGV). config - The Hash of configuration options to send to Slop.new(). block - An optional block used to add options.
Examples:
Slop.parse(ARGV, :help => true) do on '-n', '--name', 'Your username', :argument => true end
Fetch a Slop::Option object.
key - The Symbol or String option key.
Examples:
opts.on(:foo, 'Something fooey', :argument => :optional) opt = opts.fetch_option(:foo) opt.class #=> Slop::Option opt.accepts_optional_argument? #=> true
Returns an Option or nil if none were found.
Add an Option.
objects - An Array with an optional Hash as the last element.
Examples:
on '-u', '--username=', 'Your username' on :v, :verbose, 'Enable verbose mode'
Returns the created instance of Slop::Option.
Parse a list of items, executing and gathering options along the way.
items - The Array of items to extract options from (default: ARGV). block - An optional block which when used will yield non options.
Returns an Array of original items.
Parse a list of items, executing and gathering options along the way. unlike parse() this method will remove any options and option arguments from the original Array.
items - The Array of items to extract options from (default: ARGV). block - An optional block which when used will yield non options.
Returns an Array of original items with options removed.
Check for an options presence.
Examples:
opts.parse %w( --foo ) opts.present?(:foo) #=> true opts.present?(:bar) #=> false
Returns true if all of the keys are present in the parsed arguments.
Override this method so we can check if an option? method exists.
Returns true if this option key exists in our list of options.