Class: FluidCLI::Options
- Inherits:
-
Object
- Object
- FluidCLI::Options
- Defined in:
- lib/fluid_cli/options.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#subcommand ⇒ Object
readonly
Returns the value of attribute subcommand.
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #parse(options_block, args) ⇒ Object
- #parse_flags(block) ⇒ Object
- #parser ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
9 10 11 12 |
# File 'lib/fluid_cli/options.rb', line 9 def initialize @flags = {} @help = false end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
7 8 9 |
# File 'lib/fluid_cli/options.rb', line 7 def flags @flags end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
7 8 9 |
# File 'lib/fluid_cli/options.rb', line 7 def help @help end |
#subcommand ⇒ Object (readonly)
Returns the value of attribute subcommand.
7 8 9 |
# File 'lib/fluid_cli/options.rb', line 7 def subcommand @subcommand end |
Instance Method Details
#parse(options_block, args) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/fluid_cli/options.rb', line 14 def parse(, args) @args = args if .respond_to?(:call) && args parse_flags() else parser.permute!(@args) end @args end |
#parse_flags(block) ⇒ Object
24 25 26 27 |
# File 'lib/fluid_cli/options.rb', line 24 def parse_flags(block) block.call(parser, @flags) parser.permute!(@args) end |
#parser ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fluid_cli/options.rb', line 29 def parser @parser ||= begin opt = OptionParser.new opt.on("--help", "-h", "options help") do |v| @help = v end end end |