Class: ChefDK::Command::Export
- Includes:
- ChefDK::Configurable
- Defined in:
- lib/chef-dk/command/export.rb
Instance Attribute Summary collapse
-
#export_dir ⇒ Object
readonly
Returns the value of attribute export_dir.
-
#policyfile_relative_path ⇒ Object
readonly
Returns the value of attribute policyfile_relative_path.
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #apply_params!(params) ⇒ Object
- #archive? ⇒ Boolean
- #debug? ⇒ Boolean
- #export_service ⇒ Object
- #export_target ⇒ Object
- #handle_error(error) ⇒ Object
-
#initialize(*args) ⇒ Export
constructor
A new instance of Export.
- #run(params = []) ⇒ Object
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
Instance Attribute Details
#export_dir ⇒ Object (readonly)
Returns the value of attribute export_dir.
71 72 73 |
# File 'lib/chef-dk/command/export.rb', line 71 def export_dir @export_dir end |
#policyfile_relative_path ⇒ Object (readonly)
Returns the value of attribute policyfile_relative_path.
70 71 72 |
# File 'lib/chef-dk/command/export.rb', line 70 def policyfile_relative_path @policyfile_relative_path end |
#ui ⇒ Object
Returns the value of attribute ui.
73 74 75 |
# File 'lib/chef-dk/command/export.rb', line 73 def ui @ui end |
Instance Method Details
#apply_params!(params) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/chef-dk/command/export.rb', line 140 def apply_params!(params) remaining_args = (params) case remaining_args.size when 1 @export_dir = remaining_args[0] when 2 @policyfile_relative_path, @export_dir = remaining_args else ui.err(opt_parser) ui.err("\n") return false end true end |
#archive? ⇒ Boolean
118 119 120 |
# File 'lib/chef-dk/command/export.rb', line 118 def archive? !!config[:archive] end |
#debug? ⇒ Boolean
114 115 116 |
# File 'lib/chef-dk/command/export.rb', line 114 def debug? !!config[:debug] end |
#export_service ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/chef-dk/command/export.rb', line 122 def export_service @export_service ||= PolicyfileServices::ExportRepo.new(policyfile: policyfile_relative_path, export_dir: export_dir, root_dir: Dir.pwd, archive: archive?, force: config[:force]) end |
#export_target ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/chef-dk/command/export.rb', line 106 def export_target if archive? export_service.archive_file_location else export_dir end end |
#handle_error(error) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/chef-dk/command/export.rb', line 130 def handle_error(error) ui.err("Error: #{error.}") 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 |
#run(params = []) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/chef-dk/command/export.rb', line 85 def run(params = []) return 1 unless apply_params!(params) export_service.run ui.msg("Exported policy '#{export_service.policyfile_lock.name}' to #{export_target}") unless archive? ui.msg("") ui.msg("To converge this system with the exported policy, run:") ui.msg(" cd #{export_dir}") ui.msg(" #{ChefDK::Dist::INFRA_CLIENT_CLI} -z") end 0 rescue ExportDirNotEmpty => e ui.err("ERROR: " + e.) ui.err("Use --force to force export") 1 rescue PolicyfileServiceError => e handle_error(e) 1 end |