class ChefDK::Command::CleanPolicyCookbooks

Attributes

policy_group[R]
policy_name[R]
ui[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method ChefDK::Command::Base::new
# File lib/chef-dk/command/clean_policy_cookbooks.rb, line 65
def initialize(*args)
  super
  @ui = UI.new

  @clean_policy_cookbooks_service = nil
end

Public Instance Methods

apply_params!(params) click to toggle source
# File lib/chef-dk/command/clean_policy_cookbooks.rb, line 101
def apply_params!(params)
  remaining_args = parse_options(params)

  if !remaining_args.empty?
    ui.err("Too many arguments")
    ui.err("")
    ui.err(opt_parser)
    false
  else
    true
  end
end
clean_policy_cookbooks_service() click to toggle source
# File lib/chef-dk/command/clean_policy_cookbooks.rb, line 82
def clean_policy_cookbooks_service
  @clean_policy_cookbooks_service ||=
    PolicyfileServices::CleanPolicyCookbooks.new(config: chef_config, ui: ui)
end
debug?() click to toggle source
# File lib/chef-dk/command/clean_policy_cookbooks.rb, line 87
def debug?
  !!config[:debug]
end
handle_error(error) click to toggle source
# File lib/chef-dk/command/clean_policy_cookbooks.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
run(params) click to toggle source
# File lib/chef-dk/command/clean_policy_cookbooks.rb, line 72
def run(params)
  return 1 unless apply_params!(params)

  clean_policy_cookbooks_service.run
  0
rescue PolicyfileServiceError => e
  handle_error(e)
  1
end