Class: Kettle::Family::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/family/cli.rb

Constant Summary collapse

COMMANDS =
%w[discover plan report metadata check test lint docs template bump-version release branch-lanes release-state].freeze
WORKFLOW_COMMANDS =
%w[check test lint docs template release].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out:, err:) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
# File 'lib/kettle/family/cli.rb', line 16

def initialize(argv, out:, err:)
  @argv = argv.dup
  @out = out
  @err = err
end

Class Method Details

.call(argv, out: $stdout, err: $stderr) ⇒ Object



12
13
14
# File 'lib/kettle/family/cli.rb', line 12

def self.call(argv, out: $stdout, err: $stderr)
  new(argv, out: out, err: err).call
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kettle/family/cli.rb', line 22

def call
  command = argv.shift || "help"
  return help if command == "help" || command == "--help" || command == "-h"

  raise Error, "unknown command #{command.inspect}" unless COMMANDS.include?(command)

  target_version = argv.shift if command == "bump-version"
  raise Error, "bump-version requires VERSION" if command == "bump-version" && !target_version

  options = parse_options
  options[:target_version] = target_version
  return help if options.delete(:help)

  report = build_report(command, options)
  write_report(report, options)
  out.puts(options[:json] ? report.to_json : report.to_text)
  report.success? ? 0 : 1
rescue Error, OptionParser::ParseError => error
  err.puts("kettle-family: #{error.message}")
  1
end