class ChefDK::Command::Undelete

Attributes

ui[RW]
undo_record_id[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method ChefDK::Command::Base::new
# File lib/chef-dk/command/undelete.rb, line 83
def initialize(*args)
  super
  @list_undo_records = false
  @undo_record_id = nil
  @ui = UI.new
end

Public Instance Methods

apply_params!(params) click to toggle source
# File lib/chef-dk/command/undelete.rb, line 129
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
  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?() click to toggle source
# File lib/chef-dk/command/undelete.rb, line 111
def debug?
  !!config[:debug]
end
handle_error(error) click to toggle source
# File lib/chef-dk/command/undelete.rb, line 119
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
list_undo_records?() click to toggle source
# File lib/chef-dk/command/undelete.rb, line 115
def list_undo_records?
  @list_undo_records
end
run(params) click to toggle source
# File lib/chef-dk/command/undelete.rb, line 90
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() click to toggle source
# File lib/chef-dk/command/undelete.rb, line 104
def undelete_service
  @undelete_service ||=
    PolicyfileServices::Undelete.new(config: chef_config,
                                     ui: ui,
                                     undo_record_id: undo_record_id)
end