Class: Rbpw::CLI

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

Instance Method Summary collapse

Instance Method Details

#copy(key) ⇒ Object



44
45
46
# File 'lib/rbpw/cli.rb', line 44

def copy(key)
  clip_board_copy(key)
end

#delete(key) ⇒ Object



38
39
40
41
# File 'lib/rbpw/cli.rb', line 38

def delete(key)
  delete_item(key)
  puts "delete item #{key}"
end

#new(key, username = nil, password = nil) ⇒ Object



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

def new(key, username = nil , password = nil )
  # Currently, it is assumed that the data is typed on the console, so it cuts line breaks.
  if username.nil?
    puts "What's your username?"
    username = "#{$stdin.gets.chomp!}"
  end
  if password.nil?
  puts "What's your password? "
  password = "#{$stdin.gets.chomp!}"
  end
  save_to_db(set_data(key, username, password))
end

#show(key) ⇒ Object



22
23
24
25
26
# File 'lib/rbpw/cli.rb', line 22

def show(key)
  data = read_from_db(key)
  puts "username: #{data.get_username}"
  puts "password: #{data.get_password}"
end

#update(key) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rbpw/cli.rb', line 29

def update(key)
  # 例外をメソッドに書く
  data = read_from_db(key)
  puts "input change password"
  data.set_password("#{$stdin.gets.chomp!}")
  save_to_db(data)
end