Class: FluidCLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/fluid_cli/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

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

#flagsObject (readonly)

Returns the value of attribute flags.



7
8
9
# File 'lib/fluid_cli/options.rb', line 7

def flags
  @flags
end

#helpObject (readonly)

Returns the value of attribute help.



7
8
9
# File 'lib/fluid_cli/options.rb', line 7

def help
  @help
end

#subcommandObject (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(options_block, args)
  @args = args
  if options_block.respond_to?(:call) && args
    parse_flags(options_block)
  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

#parserObject



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