Class: ChefCLI::Command::Update
  
  
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #chef_config, #chefcli_config, #config_loader, #generator_config, #knife_config, #reset_config!
  
  
  
  
  
  
  
  
  Methods inherited from Base
  #check_license_acceptance, #needs_help?, #needs_version?, #run_with_default_options
  
  
  
  
  
  
  
  
  
  Methods included from Helpers
  #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_expand_path, #omnibus_install?, #omnibus_root, #package_home, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
  
  Constructor Details
  
    
  
  
    #initialize(*args)  ⇒ Update 
  
  
  
  
    
Returns a new instance of Update.
   
 
  
  
    
      
81
82
83
84
85
86
87
88
89 
     | 
    
      # 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 
     | 
  
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #policyfile_relative_path  ⇒ Object  
  
  
  
  
    
Returns the value of attribute policyfile_relative_path.
   
 
  
  
    
      
77
78
79 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 77
def policyfile_relative_path
  @policyfile_relative_path
end 
     | 
  
 
    
      
      
      
  
  
    #ui  ⇒ Object 
  
  
  
  
    
Returns the value of attribute ui.
   
 
  
  
    
      
79
80
81 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 79
def ui
  @ui
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #apply_params!(params)  ⇒ Object 
  
  
  
  
    
      
133
134
135
136
137
138 
     | 
    
      # 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  ⇒ Object 
  
  
  
  
    
      
106
107
108
109 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 106
def attributes_updater
  @attributes_updater ||=
    PolicyfileServices::UpdateAttributes.new(policyfile: policyfile_relative_path, ui:, root_dir: Dir.pwd, chef_config:)
end
     | 
  
 
    
      
  
  
    #config_path  ⇒ Object 
  
  
  
  
    
      
115
116
117 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 115
def config_path
  config[:config_file]
end 
     | 
  
 
    
      
  
  
    #debug?  ⇒ Boolean 
  
  
  
  
    
      
111
112
113 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 111
def debug?
  !!config[:debug]
end 
     | 
  
 
    
      
  
  
    #handle_error(error)  ⇒ Object 
  
  
  
  
    
      
123
124
125
126
127
128
129
130
131 
     | 
    
      # 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  ⇒ Object 
  
  
  
  
    
      
102
103
104 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 102
def installer
  @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui:, root_dir: Dir.pwd, config: chef_config, overwrite: true)
end 
     | 
  
 
    
      
  
  
    #run(params = [])  ⇒ Object 
  
  
  
  
    
      
91
92
93
94
95
96
97
98
99
100 
     | 
    
      # 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?  ⇒ Boolean 
  
  
  
  
    
      
119
120
121 
     | 
    
      # File 'lib/chef-cli/command/update.rb', line 119
def update_attributes_only?
  !!config[:update_attributes_only]
end 
     |