Module: CommandKit::Options
- Extended by:
- ModuleMethods
- Included in:
- Command, Commands, Quiet, Verbose, VerboseLevel
- Defined in:
- lib/command_kit/options.rb,
lib/command_kit/options/quiet.rb,
lib/command_kit/options/option.rb,
lib/command_kit/options/parser.rb,
lib/command_kit/options/verbose.rb,
lib/command_kit/options/version.rb,
lib/command_kit/options/option_value.rb,
lib/command_kit/options/verbose_level.rb
Overview
Provides a thin DSL for defining options as attributes.
Examples
include CommandKit::Options
option :foo, short: '-f',
value: {type: String},
desc: "Foo option"
option :bar, short: '-b',
value: {
type: String,
usage: 'STR:STR:...'
},
desc: "Bar option" do |arg|
@bar = arg.split(':')
end
Multi-line Descriptions
option :opt, value: {type: String},
desc: [
'line1',
'line2',
'...'
]
Option Categories
option :opt1, value: {type: String},
category: 'Foo Category',
desc: 'Option 1'
option :opt2, value: {type: String},
category: 'Foo Category',
desc: 'Option 2'
initialize and using instance variables
option :number, value: {type: Integer},
desc: 'Numbers' do |num|
@numbers << num
end
def initialize(**kwargs)
super(**kwargs)
@numbers = []
end
Defined Under Namespace
Modules: ClassMethods, ModuleMethods, Parser, Quiet, Verbose, VerboseLevel, Version Classes: Option, OptionValue
Constant Summary
Constants included from Printing
Instance Attribute Summary collapse
-
#options ⇒ Hash{Symbol => Object}
readonly
Hash of parsed option values.
Attributes included from Parser
Attributes included from CommandName
Instance Method Summary collapse
-
#help ⇒ Object
Overrides the default help method and calls Parser#help_options and Arguments#help_arguments.
-
#initialize(options: {}, **kwargs) ⇒ Object
Initializes #options and populates the option parser.
Methods included from ModuleMethods
Methods included from Parser
#help_options, #main, #on_ambiguous_argument, #on_ambiguous_option, #on_invalid_argument, #on_invalid_option, #on_missing_argument, #on_needless_argument, #on_parse_error, #parse_options
Methods included from Parser::ModuleMethods
Methods included from Printing
#print_error, #print_exception
Methods included from Stdio
#abort, #gets, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout
Methods included from Main
Methods included from Main::ModuleMethods
Methods included from Usage
Methods included from Usage::ModuleMethods
Methods included from Help::ModuleMethods
Methods included from CommandName::ModuleMethods
Methods included from Arguments
Methods included from Arguments::ModuleMethods
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
Hash of parsed option values.
232 233 234 |
# File 'lib/command_kit/options.rb', line 232 def @options end |
Instance Method Details
#help ⇒ Object
Overrides the default help method and calls CommandKit::Options::Parser#help_options and Arguments#help_arguments.
261 262 263 264 |
# File 'lib/command_kit/options.rb', line 261 def help help_arguments end |
#initialize(options: {}, **kwargs) ⇒ Object
The CommandKit::Options::Parser#option_parser will populate #options and also call any option blocks with the parsed option values.
Initializes #options and populates the option parser.
247 248 249 250 251 252 253 |
# File 'lib/command_kit/options.rb', line 247 def initialize(options: {}, **kwargs) @options = super(**kwargs) define_option_categories() end |