Class: ChefDK::Command::Install

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-dk/command/install.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) ⇒ Install

Returns a new instance of Install.



56
57
58
59
60
61
62
# File 'lib/chef-dk/command/install.rb', line 56

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

  @policyfile_relative_path = nil
  @installer = nil
end

Instance Attribute Details

#policyfile_relative_pathObject (readonly)

Returns the value of attribute policyfile_relative_path.



52
53
54
# File 'lib/chef-dk/command/install.rb', line 52

def policyfile_relative_path
  @policyfile_relative_path
end

#uiObject

Returns the value of attribute ui.



54
55
56
# File 'lib/chef-dk/command/install.rb', line 54

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/chef-dk/command/install.rb', line 91

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

#debug?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/chef-dk/command/install.rb', line 77

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/chef-dk/command/install.rb', line 81

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



73
74
75
# File 'lib/chef-dk/command/install.rb', line 73

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

#run(params = []) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/chef-dk/command/install.rb', line 64

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