Class: Inq::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/inq/cli.rb

Overview

Parses command-line arguments for inq.

Constant Summary collapse

MissingArgument =
Class.new(OptionParser::MissingArgument)
REPO_REGEXP =
/.+\/.+/
DATE_REGEXP =
/\d\d\d\d-\d\d-\d\d/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



22
23
24
25
# File 'lib/inq/cli.rb', line 22

def initialize
  @options = nil
  @help_text = nil
end

Instance Attribute Details

#help_textObject (readonly)

Returns the value of attribute help_text.



16
17
18
# File 'lib/inq/cli.rb', line 16

def help_text
  @help_text
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/inq/cli.rb', line 16

def options
  @options
end

Class Method Details

.parse(*args) ⇒ Object



18
19
20
# File 'lib/inq/cli.rb', line 18

def self.parse(*args)
  new.parse(*args)
end

Instance Method Details

#parse(argv) ⇒ Hash

Parses an Array of command-line arguments into an equivalent Hash.

The results of this can be used to control the behavior of the rest of the library.

Returns:

  • (Hash)

    A Hash containing data used to control Inq’s behavior.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/inq/cli.rb', line 34

def parse(argv)
  parser, options = parse_main(argv)

  # Options that are mutually-exclusive with everything else.
  options = {:help    => true} if options[:help]
  options = {:version => true} if options[:version]

  validate_options!(options)

  @options = options
  @help_text = parser.to_s

  self
end