class ChefCLI::Command::Update

Attributes

policyfile_relative_path[R]
ui[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method ChefCLI::Command::Base::new
# File lib/chef-cli/command/update.rb, line 81
def initialize(*args)
  super
  @ui = UI.new

  @policyfile_relative_path = nil
  @installer = nil
  @attributes_updater = nil
  @cookbooks_to_update = []
end

Public Instance Methods

apply_params!(params) click to toggle source
# File lib/chef-cli/command/update.rb, line 133
def apply_params!(params)
  remaining_args = parse_options(params)
  @policyfile_relative_path = remaining_args.shift
  @cookbooks_to_update += remaining_args
  true
end
attributes_updater() click to toggle source
# File lib/chef-cli/command/update.rb, line 106
def attributes_updater
  @attributes_updater ||=
    PolicyfileServices::UpdateAttributes.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, chef_config: chef_config)
end
config_path() click to toggle source
# File lib/chef-cli/command/update.rb, line 115
def config_path
  config[:config_file]
end
debug?() click to toggle source
# File lib/chef-cli/command/update.rb, line 111
def debug?
  !!config[:debug]
end
handle_error(error) click to toggle source
# File lib/chef-cli/command/update.rb, line 123
def handle_error(error)
  ui.err("Error: #{error.message}")
  if error.respond_to?(:reason)
    ui.err("Reason: #{error.reason}")
    ui.err("")
    ui.err(error.extended_error_info) if debug?
    ui.err(error.cause.backtrace.join("\n")) if debug?
  end
end
installer() click to toggle source
# File lib/chef-cli/command/update.rb, line 102
def installer
  @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, config: chef_config, overwrite: true)
end
run(params = []) click to toggle source
# File lib/chef-cli/command/update.rb, line 91
def run(params = [])
  return 1 unless apply_params!(params)

  attributes_updater.run if update_attributes_only?
  installer.run(@cookbooks_to_update, config[:exclude_deps]) unless update_attributes_only?
  0
rescue PolicyfileServiceError => e
  handle_error(e)
  1
end
update_attributes_only?() click to toggle source
# File lib/chef-cli/command/update.rb, line 119
def update_attributes_only?
  !!config[:update_attributes_only]
end