Class: Cliqr::Parser::ParsedInput Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/parser/parsed_input.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A wrapper to keep the parsed input arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_arguments) ⇒ ParsedInput

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new parsed input



24
25
26
27
28
29
30
31
32
# File 'lib/cliqr/parser/parsed_input.rb', line 24

def initialize(parsed_arguments)
  @command = parsed_arguments[:command]

  @options = Hash[parsed_arguments[:options].collect \
      { |option| [option[:name].to_s, option[:value]] }]\
      if parsed_arguments.key?(:options)

  @arguments = parsed_arguments[:arguments]
end

Instance Attribute Details

#argumentsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List of arguments from the command line

Returns:

  • (Array<String>)


21
22
23
# File 'lib/cliqr/parser/parsed_input.rb', line 21

def arguments
  @arguments
end

#commandString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Command name

Returns:

  • (String)


11
12
13
# File 'lib/cliqr/parser/parsed_input.rb', line 11

def command
  @command
end

#optionsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hash of options parsed from the command line

Returns:

  • (Hash)


16
17
18
# File 'lib/cliqr/parser/parsed_input.rb', line 16

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test equality with another object

Returns:

  • (Boolean)

    true if this object is equal to other



62
63
64
# File 'lib/cliqr/parser/parsed_input.rb', line 62

def ==(other)
  eql?(other)
end

#default_action(action_config) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get name of default action if present as option

Returns:

  • (Symbol)

    Name of the default action or nil if not present



69
70
71
72
73
74
75
76
# File 'lib/cliqr/parser/parsed_input.rb', line 69

def default_action(action_config)
  if option('help') && action_config.help?
    return :help
  elsif option('version') && action_config.version?
    return :version
  end
  nil
end

#eql?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test equality with another object

Returns:

  • (Boolean)

    true if this object is equal to other



53
54
55
56
57
# File 'lib/cliqr/parser/parsed_input.rb', line 53

def eql?(other)
  self.class.equal?(other.class) &&
    @command == other.command &&
    @options == other.options
end

#option(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a value of an option

Parameters:

  • name (String)

    Name of the option

Returns:

  • (String)


39
40
41
# File 'lib/cliqr/parser/parsed_input.rb', line 39

def option(name)
  @options[name.to_s]
end

#remove_option(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Remove a option

Returns:

  • (Object)

    Option’s original value



46
47
48
# File 'lib/cliqr/parser/parsed_input.rb', line 46

def remove_option(name)
  @options.delete(name.to_s)
end