1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 10:43:20 +00:00

new binary for wallet

This commit is contained in:
Adrien Waksberg 2016-10-19 12:56:55 +02:00
parent e196cbf93d
commit 985de310fb
2 changed files with 61 additions and 16 deletions

49
bin/mpw-wallet Normal file
View file

@ -0,0 +1,49 @@
#!/usr/bin/ruby
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'optparse'
require 'mpw/config'
require 'mpw/cli'
# --------------------------------------------------------- #
# Options
# --------------------------------------------------------- #
options = {}
OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]"
opts.on('-c', '--config CONFIG', I18n.t('option.config')) do |config|
options[:config] = config
end
opts.on('-h', '--help', I18n.t('option.help')) do
puts opts
exit 0
end
opts.on('-w', '--wallet WALLET', I18n.t('option.wallet')) do |wallet|
options[:wallet] = wallet
end
end.parse!
config = MPW::Config.new(options[:config])
cli = MPW::Cli.new(config, nil, options[:sync], nil)
cli.list_wallet

View file

@ -340,6 +340,17 @@ class Cli
Clipboard.clear Clipboard.clear
end end
# List all wallets
def list_wallet
@config.is_valid?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
wallets.each do |wallet|
puts File.basename(wallet, '.mpw')
end
end
# Display the wallet # Display the wallet
# @args: wallet -> the wallet name # @args: wallet -> the wallet name
def get_wallet(wallet=nil) def get_wallet(wallet=nil)
@ -354,22 +365,7 @@ class Cli
when 1 when 1
@wallet_file = wallets[0] @wallet_file = wallets[0]
else else
i = 1 @wallet_file = "#{@config.wallet_dir}/default.mpw"
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
exit 2
end
end end
else else
@wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw" @wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"