1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-17 08:30:04 +00:00

add choice wallet

This commit is contained in:
nishiki 2016-05-07 10:04:07 +02:00
parent f724f09957
commit 6a1d3a8921
2 changed files with 38 additions and 6 deletions

View file

@ -113,7 +113,7 @@ end.parse!
config = MPW::Config.new(options[:config])
check_error = config.checkconfig
cli = Cli.new(config, options[:wallet])
cli = Cli.new(config)
# Setup a new config
if not check_error or not options[:setup].nil?
@ -122,6 +122,7 @@ elsif not config.check_gpg_key?
cli.setup_gpg_key
end
cli.get_wallet(options[:wallet])
cli.decrypt
# Display the item's informations

View file

@ -14,12 +14,9 @@ require "#{APP_ROOT}/../lib/mpw/mpw.rb"
class Cli
# Constructor
# @args: lang -> the operating system language
# config_file -> a specify config file
# TODO
def initialize(config, wallet)
# @args: config_file -> a specify config file
def initialize(config)
@config = config
@wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"
end
# Create a new config file
@ -155,6 +152,40 @@ class Cli
puts item.comment
end
# Display the wallet
# @args: wallet -> the wallet name
def get_wallet(wallet=nil)
if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
puts wallets
case wallets.length
when 0
puts I18n.t('display.nothing')
when 1
@wallet_file = wallets[0]
else
i = 1
wallets.each do |wallet|
print "#{i}: ".cyan
puts File.basename(wallet, '.mpw')
i += 1
end
choice = ask(I18n.t('form.select')).to_i
if choice >= 1 and choice < i
@wallet_file = wallets[choice-1]
else
puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
end
end
else
@wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"
end
end
# Form to add a new item
def add
options = {}