Class: ChefDK::Command::Update

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChefDK::Configurable

#chef_config, #chefdk_config, #config_loader, #generator_config, #knife_config

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #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.



74
75
76
77
78
79
80
81
# File 'lib/chef-dk/command/update.rb', line 74

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.



70
71
72
# File 'lib/chef-dk/command/update.rb', line 70

def policyfile_relative_path
  @policyfile_relative_path
end

#uiObject

Returns the value of attribute ui.



72
73
74
# File 'lib/chef-dk/command/update.rb', line 72

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/chef-dk/command/update.rb', line 134

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



107
108
109
110
# File 'lib/chef-dk/command/update.rb', line 107

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

#config_pathObject



116
117
118
# File 'lib/chef-dk/command/update.rb', line 116

def config_path
  config[:config_file]
end

#debug?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/chef-dk/command/update.rb', line 112

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/chef-dk/command/update.rb', line 124

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



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

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

#run(params = []) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/chef-dk/command/update.rb', line 83

def run(params = [])
  return 1 unless apply_params!(params)

  # Force config file to be loaded. We don't use the configuration
  # directly, but the user may have SSL configuration options that they
  # need to talk to a private supermarket (e.g., trusted_certs or
  # ssl_verify_mode)
  chef_config

  if update_attributes?
    attributes_updater.run
  else
    installer.run
  end
  0
rescue PolicyfileServiceError => e
  handle_error(e)
  1
end

#update_attributes?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/chef-dk/command/update.rb', line 120

def update_attributes?
  !!config[:update_attributes]
end