Class: Producer::Core::CLI

Inherits:
Baf::CLI
  • Object
show all
Defined in:
lib/producer/core/cli.rb

Constant Summary collapse

ArgumentError =
Class.new(ArgumentError)
USAGE =
"Usage: #{File.basename $0} [options] [recipes] [-- recipe_argument...]"
.freeze
ARGUMENTS_SEPARATOR =
'--'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handle_error(env, ex) ⇒ Object



13
14
15
# File 'lib/producer/core/cli.rb', line 13

def handle_error env, ex
  env.puts_error ErrorFormatter.new(debug: env.debug?).format ex
end

Instance Method Details

#evaluate_recipesObject



43
44
45
# File 'lib/producer/core/cli.rb', line 43

def evaluate_recipes
  arguments.map { |e| Recipe::FileEvaluator.evaluate(e, env) }
end

#parse_arguments!Object



29
30
31
32
33
34
35
# File 'lib/producer/core/cli.rb', line 29

def parse_arguments!
  if arguments.include? ARGUMENTS_SEPARATOR
    @arguments, env.recipe_argv = split_arguments_lists arguments
  end
  super
  usage! if arguments.empty?
end

#run(worker: Worker.new(env)) ⇒ Object



37
38
39
40
41
# File 'lib/producer/core/cli.rb', line 37

def run worker: Worker.new(env)
  evaluate_recipes.each { |recipe| worker.process recipe.tasks }
ensure
  env.cleanup
end

#setupObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/producer/core/cli.rb', line 18

def setup
  banner USAGE

  flag_verbose
  flag_debug
  flag_version Producer::Core::VERSION

  flag :n, :dry_run, 'enable dry run mode'
  option :t, :target, 'HOST', 'target host'
end