Class: Foobara::CommandConnectors::ShCliConnector::ActionParser::Result

Inherits:
Object
  • Object
show all
Defined in:
foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action = nil) ⇒ Result

Returns a new instance of Result.



9
10
11
12
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 9

def initialize(action = nil)
  self.parsed = {}
  self.action = action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



7
8
9
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 7

def action
  @action
end

#argumentObject

Returns the value of attribute argument.



7
8
9
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 7

def argument
  @argument
end

#parsedObject

Returns the value of attribute parsed.



6
7
8
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 6

def parsed
  @parsed
end

#remainderObject

Returns the value of attribute remainder.



6
7
8
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 6

def remainder
  @remainder
end

Instance Method Details

#validate!Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/action_parser.rb', line 38

def validate!
  if action.nil?
    raise ParseError,
          "Found invalid option #{remainder.first} but was expecting an action like 'run' or 'help'"
  end

  if action == "run"
    unless argument
      raise ParseError, "Missing command to run"
    end
  elsif action == "describe"
    unless argument
      raise ParseError, "Missing command or type to describe"
    end
  end
end