From b83b27832e5d44e5c8cb726279b234529dcfa3ed Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Mon, 22 May 2017 21:25:56 +0200 Subject: [PATCH] feat: no ask password if not necessary --- lib/mpw/cli.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 02ede97..d92e4e4 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -126,12 +126,20 @@ module MPW # Request the GPG password and decrypt the file def decrypt - unless defined?(@mpw) - @password = ask(I18n.t('display.gpg_password')) { |q| q.echo = false } - @mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe, @config.pinmode) - end + if defined?(@mpw) + @mpw.read_data + else + begin + @mpw = MPW.new(@config.gpg_key, @wallet_file, nil, @config.gpg_exe, @config.pinmode) - @mpw.read_data + @mpw.read_data + rescue + @password = ask(I18n.t('display.gpg_password')) { |q| q.echo = false } + @mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe, @config.pinmode) + + @mpw.read_data + end + end rescue => e puts "#{I18n.t('display.error')} #11: #{e}".red exit 2