Class: Agent::SessionContext::CLI::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/session_context/cli/options.rb

Class Method Summary collapse

Class Method Details

.hinted_format(arguments) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/agent/session_context/cli/options.rb', line 89

def hinted_format(arguments)
  limit = arguments.index("--") || arguments.length
  effective = :text
  index = 0

  while index < limit
    token = arguments[index]

    if token == "--format"
      candidate = arguments[index + 1]
      effective = candidate.to_sym if CLI::FORMATS.include?(candidate)
      index += 2
      next
    end

    if token.start_with?("--format=")
      candidate = token.split("=", 2).last
      effective = candidate.to_sym if CLI::FORMATS.include?(candidate)
    end

    index += 1
  end

  effective
end

.parse(arguments, command:) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/agent/session_context/cli/options.rb', line 78

def parse(arguments, command:)
  descriptor = command_descriptor(command)
  options = default_options
  validate_argument_encoding!(arguments)
  validate_exact_long_options!(arguments, descriptor:)
  remaining = parser(options, descriptor:).permute(arguments.dup)

  validate_selection!(options, remaining, command:, descriptor:)
  options.merge(identifier: remaining.first).freeze
end

.parse_no_args(arguments, command:) ⇒ Object

Raises:

  • (OptionParser::ParseError)


115
116
117
118
119
120
121
# File 'lib/agent/session_context/cli/options.rb', line 115

def parse_no_args(arguments, command:)
  descriptor = command_descriptor(command)
  validate_argument_encoding!(arguments)
  validate_exact_long_options!(arguments, descriptor:)
  remaining = OptionParser.new.permute(arguments.dup)
  raise OptionParser::ParseError, "unexpected arguments: #{remaining.join(" ")}" unless remaining.empty?
end