Class: PasswordSafe::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/passwordsafe/cli.rb

Constant Summary collapse

DEFAULTSAFE =
'safefile'

Instance Method Summary collapse

Instance Method Details

#add(name, password) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/passwordsafe/cli.rb', line 10

def add name, password
  safe = make_safe
  begin
    PasswordSafe::Keyring.new(safe).add name, password
  rescue PasswordSafe::Keyring::KeyExistsException => msg
    puts "#{msg}"
  else
    puts "password #{name} added to safe"
  end
end

#change(name, password) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/passwordsafe/cli.rb', line 58

def change name, password
  safe = make_safe
  begin
   PasswordSafe::Keyring.new(safe).change(name, password)
  rescue PasswordSafe::Keyring::KeyMissingException => msg
    puts "#{msg}"
  else
    puts "password for #{name} has been updated"
  end
end

#generate(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/passwordsafe/cli.rb', line 23

def generate name
  safe = make_safe
  begin
    password = PasswordSafe::Keyring.new(safe).generate(name, options[:length])
  rescue PasswordSafe::Keyring::KeyExistsException => msg
    puts "#{msg}"
  else
    puts "password #{password} generated and added to safe"
  end
end

#get(name) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/passwordsafe/cli.rb', line 35

def get name
  safe = make_safe
  password = PasswordSafe::Keyring.new(safe).get name
  if password.nil?
    puts "#{name} does not exist in this safe."
  else
    puts "#{name}: #{password}"
  end
end

#listObject



70
71
72
73
74
75
# File 'lib/passwordsafe/cli.rb', line 70

def list
  safe = make_safe
  keys = PasswordSafe::Keyring.new(safe).list
  puts "List: (none)" if keys.empty?
  puts "List: #{keys.join(", ")}"
end

#remove(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/passwordsafe/cli.rb', line 46

def remove name
  safe = make_safe
  begin
   PasswordSafe::Keyring.new(safe).remove(name)
  rescue PasswordSafe::Keyring::KeyMissingException => msg
    puts "#{msg}"
  else
    puts "entry has been removed"
  end
end