class ChefCLI::Command::ShowPolicy
def apply_params!(params)
def apply_params!(params) remaining_args = parse_options(params) if remaining_args.empty? && show_summary_diff? ui.err("The --summary-diff option can only be used when showing a single policy") ui.err("") ui.err(opt_parser) false elsif remaining_args.empty? @show_all_policies = true true elsif remaining_args.size == 1 @policy_name = remaining_args.first @show_all_policies = false true elsif remaining_args.size == 2 @policy_name = remaining_args[0] @policy_group = remaining_args[1] @show_all_policies = false true else ui.err("Too many arguments") ui.err("") ui.err(opt_parser) false end end
def debug?
def debug? !!config[:debug] end
def enable_pager?
def enable_pager? config[:pager] end
def handle_error(error)
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
def initialize(*args)
def initialize(*args) super @show_all_policies = nil @policy_name = nil @policy_group = nil @ui = UI.new end
def run(params)
def run(params) return 1 unless apply_params!(params) show_policy_service.run 0 rescue PolicyfileServiceError => e handle_error(e) 1 end
def show_orphans?
def show_orphans? config[:show_orphans] end
def show_policy_service
def show_policy_service @policy_list_service ||= PolicyfileServices::ShowPolicy.new(config: chef_config, ui: ui, policy_name: policy_name, policy_group: policy_group, show_orphans: show_orphans?, summary_diff: show_summary_diff?, pager: enable_pager?) end
def show_summary_diff?
def show_summary_diff? false end