Class: Foobara::CommandConnectors::ShCliConnector::Request

Inherits:
Foobara::CommandConnector::Request show all
Defined in:
foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes inherited from Foobara::CommandConnector::Request

#command_class, #command_connector, #error, #response, #serializers

Instance Method Summary collapse

Methods inherited from Foobara::CommandConnector::Request

#error_collection, #outcome, #response_body, #result, #serializer, #success?

Methods included from TruncatedInspect

#inspect, truncating

Constructor Details

#initialize(argv, command:, exit: true, stdout: $stdout, stderr: $stderr, stdin: $stdin) ⇒ Request

Returns a new instance of Request.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 20

def initialize(argv, command:, exit: true, stdout: $stdout, stderr: $stderr, stdin: $stdin)
  self.command = command
  self.argv = argv
  self.exit = exit
  self.stdin = stdin
  self.stdout = stdout
  self.stderr = stderr

  begin
    parse!
  rescue ParseError => e
    self.error = e
  end

  super()
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/request.rb', line 7

def action
  @action
end

#action_optionsObject

Returns the value of attribute action_options.



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

def action_options
  @action_options
end

#argumentObject

Returns the value of attribute argument.



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

def argument
  @argument
end

#argvObject

Returns the value of attribute argv.



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

def argv
  @argv
end

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#exitObject

Returns the value of attribute exit.



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

def exit
  @exit
end

#globalish_optionsObject

Returns the value of attribute globalish_options.



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

def globalish_options
  @globalish_options
end

#inputs_argvObject

Returns the value of attribute inputs_argv.



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

def inputs_argv
  @inputs_argv
end

#single_command_modeObject

Returns the value of attribute single_command_mode.



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

def single_command_mode
  @single_command_mode
end

#stderrObject

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#action_parserObject



89
90
91
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 89

def action_parser
  @action_parser ||= ActionParser.new
end

#full_command_nameObject

TODO: we might not have the full command name here… that should be fine. TODO: rename this.



64
65
66
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 64

def full_command_name
  argument
end

#globalish_parserObject



85
86
87
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 85

def globalish_parser
  @globalish_parser ||= GlobalishParser.new
end

#input_serializerObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 41

def input_serializer
  @input_serializer ||= begin
    input_format = globalish_options[:input_format]

    serializer_class = if input_format.nil?
                         # TODO: refactor this to some default setting
                         Foobara::CommandConnectors::Serializers::YamlSerializer
                       else
                         Serializer.serializer_from_symbol(input_format)
                       end

    unless serializer_class
      # :nocov:
      raise ParseError, "Unknown input format: #{input_format}"
      # :nocov:
    end

    serializer_class.new(nil)
  end
end

#inputsObject



68
69
70
71
72
73
74
75
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 68

def inputs
  @inputs ||= if globalish_options[:stdin]
                input_serializer.deserialize(stdin.read)
              else
                result = inputs_parser.parse(inputs_argv)
                result.parsed
              end
end

#inputs_parserObject



77
78
79
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 77

def inputs_parser
  @inputs_parser ||= inputs_parser_for
end

#inputs_parser_for(command_class = self.command_class) ⇒ Object



81
82
83
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 81

def inputs_parser_for(command_class = self.command_class)
  InputsParser.new(command_class.inputs_type, always_prefix_inputs: command_connector.always_prefix_inputs)
end

#single_command_mode?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/request.rb', line 37

def single_command_mode?
  !!command
end