class ChefCLI::Command::DeletePolicy
Attributes
policy_name[R]
ui[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
ChefCLI::Command::Base::new
# File lib/chef-cli/command/delete_policy.rb, line 62 def initialize(*args) super @policy_name = nil @rm_policy_service = nil @ui = UI.new end
Public Instance Methods
apply_params!(params)
click to toggle source
# File lib/chef-cli/command/delete_policy.rb, line 101 def apply_params!(params) remaining_args = parse_options(params) if remaining_args.size == 1 @policy_name = remaining_args.first true elsif remaining_args.empty? ui.err("You must specify the POLICY_NAME to delete.") ui.err("") ui.err(opt_parser) false else ui.err("Too many arguments") ui.err("") ui.err(opt_parser) false end end
debug?()
click to toggle source
# File lib/chef-cli/command/delete_policy.rb, line 87 def debug? !!config[:debug] end
handle_error(error)
click to toggle source
# File lib/chef-cli/command/delete_policy.rb, line 91 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
rm_policy_service()
click to toggle source
# File lib/chef-cli/command/delete_policy.rb, line 80 def rm_policy_service @rm_policy_service ||= PolicyfileServices::RmPolicy.new(config: chef_config, ui: ui, policy_name: policy_name) end
run(params)
click to toggle source
# File lib/chef-cli/command/delete_policy.rb, line 69 def run(params) return 1 unless apply_params!(params) rm_policy_service.run ui.msg("This operation can be reversed by running `#{ChefCLI::Dist::EXEC} undelete --last`.") 0 rescue PolicyfileServiceError => e handle_error(e) 1 end