Class: ChefDK::Command::CleanPolicyRevisions

Inherits:
Base
  • Object
show all
Includes:
ChefDK::Configurable
Defined in:
lib/chef-dk/command/clean_policy_revisions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initialize(*args) ⇒ CleanPolicyRevisions

Returns a new instance of CleanPolicyRevisions.



64
65
66
67
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 64

def initialize(*args)
  super
  @ui = UI.new
end

Instance Attribute Details

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



62
63
64
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 62

def policy_group
  @policy_group
end

#policy_nameObject (readonly)

Returns the value of attribute policy_name.



60
61
62
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 60

def policy_name
  @policy_name
end

#uiObject

Returns the value of attribute ui.



58
59
60
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 58

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 98

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_policies_serviceObject



79
80
81
82
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 79

def clean_policies_service
  @policy_list_service ||=
    PolicyfileServices::CleanPolicies.new(config: chef_config, ui: ui)
end

#debug?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 84

def debug?
  !!config[:debug]
end

#handle_error(error) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 88

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) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/chef-dk/command/clean_policy_revisions.rb', line 69

def run(params)
  return 1 unless apply_params!(params)

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