From 985de310fb4f11f4f00c92a196e9a7e2632c07c7 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Wed, 19 Oct 2016 12:56:55 +0200 Subject: [PATCH] new binary for wallet --- bin/mpw-wallet | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/mpw/cli.rb | 28 ++++++++++++---------------- 2 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 bin/mpw-wallet diff --git a/bin/mpw-wallet b/bin/mpw-wallet new file mode 100644 index 0000000..c5fdc7a --- /dev/null +++ b/bin/mpw-wallet @@ -0,0 +1,49 @@ +#!/usr/bin/ruby +# MPW is a software to crypt and manage your passwords +# Copyright (C) 2016 Adrien Waksberg +# +# 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 diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 749007a..b92d5fb 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -340,6 +340,17 @@ class Cli Clipboard.clear 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 # @args: wallet -> the wallet name def get_wallet(wallet=nil) @@ -354,22 +365,7 @@ class Cli 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 - exit 2 - end + @wallet_file = "#{@config.wallet_dir}/default.mpw" end else @wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw"