Class: Pwl::Commands::Add

Inherits:
Base
  • Object
show all
Defined in:
lib/pwl/commands/add.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
24
25
26
27
28
29
30
31
32
33
# File 'lib/pwl/commands/add.rb', line 4

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

  # Ask for the master password _before_ it may be necessary to ask for the value in a terminal
  begin
    locker = open_locker(options)
  rescue Pwl::Dialog::Cancelled
    exit_with(:aborted, options.verbose)
  end

  value = args[1]

  if !value
    exit_with(:value_blank, options.verbose) unless STDIN.tty? || options.gui

    begin
      value = get_text("Enter value for name '#{args[0]}':", options.gui)
    rescue Pwl::Dialog::Cancelled
      exit_with(:aborted, options.verbose)
    end

    # still blank, even after asking for it?
    if value.blank?
      exit_with(:value_blank, true)
    end
  end

  locker.add(args[0], value)
  msg "Successfully stored new value under #{args[0]}." if options.verbose
end