Class: ChefDK::Command::Push

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChefDK::Configurable

#chef_config, #chefdk_config, #config_loader

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#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) ⇒ Push

Returns a new instance of Push.



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

def initialize(*args)
  super
  @push = nil
  @ui = nil
  @policy_group = nil
  @policyfile_relative_path = nil
  @chef_config = nil
  @ui = UI.new
end

Instance Attribute Details

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



59
60
61
# File 'lib/chef-dk/command/push.rb', line 59

def policy_group
  @policy_group
end

#policyfile_relative_pathObject (readonly)

Returns the value of attribute policyfile_relative_path.



58
59
60
# File 'lib/chef-dk/command/push.rb', line 58

def policyfile_relative_path
  @policyfile_relative_path
end

#uiObject

Returns the value of attribute ui.



61
62
63
# File 'lib/chef-dk/command/push.rb', line 61

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



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

def apply_params!(params)
  remaining_args = parse_options(params)
  if remaining_args.size < 1 or remaining_args.size > 2
    ui.err(opt_parser)
    return false
  else
    @policy_group = remaining_args[0]
    @policyfile_relative_path = remaining_args[1]
  end
  true
end

#debug?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/chef-dk/command/push.rb', line 82

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/chef-dk/command/push.rb', line 94

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

#pushObject



86
87
88
89
90
91
92
# File 'lib/chef-dk/command/push.rb', line 86

def push
  @push ||= PolicyfileServices::Push.new(policyfile: policyfile_relative_path,
                                         ui: ui,
                                         policy_group: policy_group,
                                         config: chef_config,
                                         root_dir: Dir.pwd)
end

#run(params = []) ⇒ Object



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

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