Class: TWPipeline::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/twpipeline/cli.rb,
sig/twpipeline.rbs

Constant Summary collapse

COMMANDS =

Returns:

  • (::Array[::String])
%w[run check stages resources].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • argv (::Array[::String])


11
12
13
14
# File 'lib/twpipeline/cli.rb', line 11

def initialize(argv)
  @argv = argv.dup
  @options = {}
end

Class Method Details

.call(argv) ⇒ ::Integer

Parameters:

  • argv (::Array[::String])

Returns:

  • (::Integer)


9
# File 'lib/twpipeline/cli.rb', line 9

def self.call(argv) = new(argv).call

Instance Method Details

#call::Integer

Returns:

  • (::Integer)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twpipeline/cli.rb', line 16

def call
  parser.parse!(@argv, into: parsed = {})
  @options = parsed.transform_keys { |key| key.to_s.tr("-", "_").to_sym }
  TWPipeline.resources = resources
  TWPipeline.warm_up

  case @argv.shift
  in nil
    abort(parser.to_s)
  in "run"
    run
  in "check"
    check
  in "stages"
    stages
  in "resources"
    $stdout.puts(resources.to_s)
  in name
    stage(name)
  end

  0
rescue Error, TWFilter::Error => error
  warn("twpipeline: #{error.message}")
  1
end