Class: Itamae::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/itamae/cli.rb

Constant Summary collapse

GENERATE_TARGETS =
%w[cookbook role].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



8
9
10
11
12
13
# File 'lib/itamae/cli.rb', line 8

def initialize(*)
  super

  Itamae.logger.level = ::Logger.const_get(options[:log_level].upcase) if options[:log_level]
  Itamae.logger.formatter.colored = options[:color] if options[:color]
end

Class Method Details

.define_exec_optionsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/itamae/cli.rb', line 15

def self.define_exec_options
  option :recipe_graph, type: :string, desc: "[EXPERIMENTAL] Write recipe dependency graph in DOT", banner: "PATH"
  option :node_json, type: :string, aliases: ['-j'], repeatable: true
  option :node_yaml, type: :string, aliases: ['-y'], repeatable: true
  option :dry_run, type: :boolean, aliases: ['-n']
  option :shell, type: :string, default: "/bin/sh"
  option :login_shell, type: :boolean, default: false
  option :ohai, type: :boolean, default: false, desc: "This option is DEPRECATED and will be unavailable."
  option :profile, type: :string, desc: "[EXPERIMENTAL] Save profiling data", banner: "PATH"
  option :detailed_exitcode, type: :boolean, default: false, desc: "exit code 0 - The run succeeded with no changes or failures, exit code 1 - The run failed, exit code 2 - The run succeeded, and some resources were changed"
  option :log_level, type: :string, aliases: ['-l'], default: 'info'
  option :color, type: :boolean, default: true
  option :config, type: :string, aliases: ['-c']
  option :tmp_dir, type: :string, aliases: ['-t'], default: "/tmp/itamae_tmp"
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/itamae/cli.rb', line 39

def self.exit_on_failure?
  true
end

.optionsObject



31
32
33
34
35
36
37
# File 'lib/itamae/cli.rb', line 31

def self.options
  @itamae_options ||= super.dup.tap do |options|
    if config = options[:config]
      options.merge!(YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(config) : YAML.load(config))
    end
  end
end

Instance Method Details

#destroy(target, name) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/itamae/cli.rb', line 124

def destroy(target, name)
  validate_generate_target!('destroy', target)

  generator = Generators.find(target).new
  generator.destination_root = File.join("#{target}s", name)
  generator.remove_files
end

#docker(*recipe_files) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/itamae/cli.rb', line 81

def docker(*recipe_files)
  if recipe_files.empty?
    raise "Please specify recipe files."
  end

  run(recipe_files, :docker, options)
end

#generate(target, name) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/itamae/cli.rb', line 114

def generate(target, name)
  validate_generate_target!('generate', target)

  generator = Generators.find(target).new
  generator.destination_root = File.join("#{target}s", name)
  generator.copy_files
end

#init(name) ⇒ Object



106
107
108
109
110
# File 'lib/itamae/cli.rb', line 106

def init(name)
  generator = Generators::Project.new
  generator.destination_root = name
  generator.invoke_all
end

#jail(*recipe_files) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/itamae/cli.rb', line 92

def jail(*recipe_files)
  if recipe_files.empty?
    raise "Please specify recipe files."
  end

  run(recipe_files, :jexec, options)
end

#local(*recipe_files) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/itamae/cli.rb', line 45

def local(*recipe_files)
  if recipe_files.empty?
    raise "Please specify recipe files."
  end

  run(recipe_files, :local, options)
end

#ssh(*recipe_files) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/itamae/cli.rb', line 63

def ssh(*recipe_files)
  if recipe_files.empty?
    raise "Please specify recipe files."
  end

  unless options[:host] || options[:vagrant]
    raise "Please set '-h <hostname>' or '--vagrant'"
  end

  run(recipe_files, :ssh, options)
end

#versionObject



101
102
103
# File 'lib/itamae/cli.rb', line 101

def version
  puts "Itamae v#{Itamae::VERSION}"
end