Class: ChefDK::Command::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-dk/command/update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command

Constructor Details

#initialize(*args) ⇒ Update

Returns a new instance of Update.



67
68
69
70
71
72
73
74
# File 'lib/chef-dk/command/update.rb', line 67

def initialize(*args)
  super
  @ui = UI.new

  @policyfile_relative_path = nil
  @installer = nil
  @attributes_updater = nil
end

Instance Attribute Details

#policyfile_relative_pathObject (readonly)

Returns the value of attribute policyfile_relative_path.



63
64
65
# File 'lib/chef-dk/command/update.rb', line 63

def policyfile_relative_path
  @policyfile_relative_path
end

#uiObject

Returns the value of attribute ui.



65
66
67
# File 'lib/chef-dk/command/update.rb', line 65

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/chef-dk/command/update.rb', line 116

def apply_params!(params)
  remaining_args = parse_options(params)
  if remaining_args.size > 1
    ui.err(banner)
    return 1
  else
    @policyfile_relative_path = remaining_args.first
  end
end

#attributes_updaterObject



93
94
95
96
# File 'lib/chef-dk/command/update.rb', line 93

def attributes_updater
  @attributes_updater ||=
    PolicyfileServices::UpdateAttributes.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd)
end

#debug?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/chef-dk/command/update.rb', line 98

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/chef-dk/command/update.rb', line 106

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

#installerObject



89
90
91
# File 'lib/chef-dk/command/update.rb', line 89

def installer
  @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, overwrite: true)
end

#run(params = []) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/chef-dk/command/update.rb', line 76

def run(params = [])
  apply_params!(params)
  if update_attributes?
    attributes_updater.run
  else
    installer.run
  end
  0
rescue PolicyfileServiceError => e
  handle_error(e)
  1
end

#update_attributes?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/chef-dk/command/update.rb', line 102

def update_attributes?
  !!config[:update_attributes]
end