Class: Pwl::Commands::Get

Inherits:
Base
  • Object
show all
Defined in:
lib/pwl/commands/get.rb

Instance Method Summary collapse

Methods inherited from Base

default_locker_file, exit_codes_help

Instance Method Details

#call(args, options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pwl/commands/get.rb', line 4

def call(args, options)
  exit_with(:name_blank, options.verbose) if 0 == args.size || args[0].blank?

  # second argument can be a field other than password
  field = args.size > 1 ? args[1] : 'password'

  begin
    locker = open_locker(options)
    result = attr!(locker.get(args[0]), field)
    if result.blank?
      exit_with(:no_value_found, options.verbose, :name => args[0])
    else
      puts result
    end
  rescue InacessibleFieldError
    exit_with(:inaccessible_field, options.verbose, :field => field)
  rescue Dialog::Cancelled
    exit_with(:aborted, options.verbose)
  end
end