Class: ChefCLI::Command::PushArchive

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChefCLI::Configurable

#chef_config, #chefcli_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

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

Returns a new instance of PushArchive.



52
53
54
55
56
57
58
# File 'lib/chef-cli/command/push_archive.rb', line 52

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.



50
51
52
# File 'lib/chef-cli/command/push_archive.rb', line 50

def archive_path
  @archive_path
end

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



48
49
50
# File 'lib/chef-cli/command/push_archive.rb', line 48

def policy_group
  @policy_group
end

#uiObject

Returns the value of attribute ui.



46
47
48
# File 'lib/chef-cli/command/push_archive.rb', line 46

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.



103
104
105
106
107
108
109
110
111
# File 'lib/chef-cli/command/push_archive.rb', line 103

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



93
94
95
# File 'lib/chef-cli/command/push_archive.rb', line 93

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)


98
99
100
# File 'lib/chef-cli/command/push_archive.rb', line 98

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.



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

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.



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

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

#run(params) ⇒ Object



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

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

  push_archive_service.run

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