class ChefCLI::Command::Undelete

def apply_params!(params)

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

def debug?

def debug?
  !!config[:debug]
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
  @list_undo_records = false
  @undo_record_id = nil
  @ui = UI.new
end

def list_undo_records?

def list_undo_records?
  @list_undo_records
end

def run(params)

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

def undelete_service

def undelete_service
  @undelete_service ||=
    PolicyfileServices::Undelete.new(config: chef_config,
                                     ui: ui,
                                     undo_record_id: undo_record_id)
end