Class: ChefCLI::Command::Undelete
- Includes:
- ChefCLI::Configurable
- Defined in:
- lib/chef-cli/command/undelete.rb
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
-
#undo_record_id ⇒ Object
readonly
Returns the value of attribute undo_record_id.
Instance Method Summary collapse
- #apply_params!(params) ⇒ Object
- #debug? ⇒ Boolean
- #handle_error(error) ⇒ Object
-
#initialize(*args) ⇒ Undelete
constructor
A new instance of Undelete.
- #list_undo_records? ⇒ Boolean
- #run(params) ⇒ Object
- #undelete_service ⇒ Object
Methods included from ChefCLI::Configurable
#chef_config, #chefcli_config, #config_loader, #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
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
68 69 70 |
# File 'lib/chef-cli/command/undelete.rb', line 68 def ui @ui end |
#undo_record_id ⇒ Object (readonly)
Returns the value of attribute undo_record_id.
70 71 72 |
# File 'lib/chef-cli/command/undelete.rb', line 70 def undo_record_id @undo_record_id end |
Instance Method Details
#apply_params!(params) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/chef-cli/command/undelete.rb', line 118 def apply_params!(params) remaining_args = (params) if !remaining_args.empty? ui.err("Too many arguments") ui.err("") ui.err(opt_parser) false elsif config[:undo_record_id].nil? && config[:undo_last].nil? @list_undo_records = true true elsif config[:undo_record_id] && config[:undo_last] ui.err("Error: options --last and --id cannot both be given.") ui.err("") ui.err(opt_parser) false elsif config[:undo_record_id] @undo_record_id = config[:undo_record_id] true elsif config[:undo_last] @undo_record_id = nil true end end |
#debug? ⇒ Boolean
100 101 102 |
# File 'lib/chef-cli/command/undelete.rb', line 100 def debug? !!config[:debug] end |
#handle_error(error) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/chef-cli/command/undelete.rb', line 108 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 |
#list_undo_records? ⇒ Boolean
104 105 106 |
# File 'lib/chef-cli/command/undelete.rb', line 104 def list_undo_records? @list_undo_records end |
#run(params) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/chef-cli/command/undelete.rb', line 79 def run(params) return 1 unless apply_params!(params) if list_undo_records? undelete_service.list else undelete_service.run end 0 rescue PolicyfileServiceError => e handle_error(e) 1 end |
#undelete_service ⇒ Object
93 94 95 96 97 98 |
# File 'lib/chef-cli/command/undelete.rb', line 93 def undelete_service @undelete_service ||= PolicyfileServices::Undelete.new(config: chef_config, ui:, undo_record_id:) end |