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, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initialize(*args) ⇒ Update

Returns a new instance of Update.



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

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.



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

def policyfile_relative_path
  @policyfile_relative_path
end

#uiObject

Returns the value of attribute ui.



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

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



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

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

#attributes_updaterObject



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



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

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



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

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

#run(params = []) ⇒ Object



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

def run(params = [])
  return 1 unless 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)


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

def update_attributes?
  !!config[:update_attributes]
end