Class: ArgsParser

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

Overview

Processes the array of arguments (ARGV by default) and returns the options, targets, and help string.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  as_array: false,
  format: 'at', # AwesomePrint for metadata, to_s for text content
  metadata: true,
  text: true,
  source: true,
  key_sort: true
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(args = ARGV) ⇒ Array<Hash,String>

Parses the command line arguments. Shorthand for ArgsParser.new.call. This call is recommended to pro tect the caller in case this functionality is repackaged as a Module or otherwise modified.

Parameters:

  • args (Array) (defaults to: ARGV)

    the command line arguments (overridable for testing, etc.)

Returns:

  • (Array<Hash,String>)

    [options, targets, help_string], or exits if help or version requested or no targets specified.



24
25
26
# File 'lib/rika/cli/args_parser.rb', line 24

def self.call(args = ARGV)
  new.call(args)
end

Instance Method Details

#call(args = ARGV) ⇒ Array<Hash,String>

Parses the command line arguments.

Parameters:

  • args (Array) (defaults to: ARGV)

    the command line arguments (overridable for testing, etc.)

Returns:

  • (Array<Hash,String>)

    [options, targets, help_string], or exits if help or version requested or no targets specified.



32
33
34
35
36
37
38
39
40
41
# File 'lib/rika/cli/args_parser.rb', line 32

def call(args = ARGV)
  @args = args
  @options = DEFAULT_OPTIONS.dup
  prepend_environment_args
  @option_parser = create_option_parser
  option_parser.parse!(args)
  postprocess_format_options
  targets = create_target_array
  [options, targets, option_parser.help]
end