Class: ChefDK::Command::PushArchive

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChefDK::Configurable

#chef_config, #chefdk_config, #config_loader, #default_chef_server_http_client, #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

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

Returns a new instance of PushArchive.



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

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

Instance Attribute Details

#archive_pathObject (readonly)

Returns the value of attribute archive_path.



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

def archive_path
  @archive_path
end

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



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

def policy_group
  @policy_group
end

#uiObject

Returns the value of attribute ui.



57
58
59
# File 'lib/chef-dk/command/push_archive.rb', line 57

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def apply_params!(params)
  remaining_args = parse_options(params)
  if remaining_args.size != 2
    ui.err(opt_parser)
    return false
  end

  @policy_group, @archive_path = remaining_args
end

#archive_fileObject



104
105
106
# File 'lib/chef-dk/command/push_archive.rb', line 104

def archive_file
  File.expand_path(archive_path)
end

#debug?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


109
110
111
# File 'lib/chef-dk/command/push_archive.rb', line 109

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



83
84
85
86
87
88
89
90
91
# File 'lib/chef-dk/command/push_archive.rb', line 83

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

#push_archive_serviceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def push_archive_service
  @push_archive_service ||=
    ChefDK::PolicyfileServices::PushArchive.new(
      archive_file: archive_file,
      policy_group: policy_group,
      ui: ui,
      config: chef_config
    )
end

#run(params) ⇒ Object



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

def run(params)
  return 1 unless apply_params!(params)

  push_archive_service.run

  0
rescue PolicyfileServiceError => e
  handle_error(e)
  1
end