Class: Fission::CommandLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fission/command_line_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CommandLineParser

Internal: Creates a new Fission::CommandLineParser object.

args - The command line arguments to parse. This is expected to be in the same format of ARGV (Array) (default: ARGV).

Examples:

CommandLineParser.new ['foo', 'bar']

CommandLineParser.new

Returns a Fission::CommandLineParser object.



17
18
19
20
21
22
23
# File 'lib/fission/command_line_parser.rb', line 17

def initialize(args=ARGV)
  @args = args

  gather_commands_and_summaries

  setup_options_parser
end

Instance Method Details

#commandObject

Internal: Accessor for an instance of the determined command. This is set by running the parse method.

Examples:

@command_line_parser.command

Returns an instance of the determined command if the arguments are valid. Returns nil if the parse command has not yet been run.



55
56
57
# File 'lib/fission/command_line_parser.rb', line 55

def command
  @command
end

#parseObject

Internal: Parses the command line arguments. If the arguments are invalid, the appropriate help will be output and then will exit. If the arguments are valid, then the @command variable will be set to a new instance of the determined command class.

Examples:

@command_line_parser.parse

Returns nothing.



35
36
37
38
39
40
41
42
43
44
# File 'lib/fission/command_line_parser.rb', line 35

def parse
  @options_parser.order! @args

  determine_command_provided
  self
rescue OptionParser::InvalidOption => e
  ui.output e
  show_all_help
  exit 1
end