From 7b301519b64213b9765c1e7e7bbefaeefc680e67 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 20 Oct 2016 21:25:43 +0200 Subject: [PATCH] config: fix init with existing gpg key --- bin/mpw-config | 17 ++++++++++------- lib/mpw/cli.rb | 11 +++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/mpw-config b/bin/mpw-config index a1b0743..b0a1863 100644 --- a/bin/mpw-config +++ b/bin/mpw-config @@ -25,6 +25,7 @@ require 'mpw/cli' # --------------------------------------------------------- # options = {} +values = {} OptionParser.new do |opts| opts.banner = "#{I18n.t('option.usage')}: mpw config [options]" @@ -34,7 +35,7 @@ OptionParser.new do |opts| end opts.on('-g', '--gpg-exe PATH', I18n.t('option.gpg_exe')) do |gpg_exe| - options[:gpg_exe] = gpg_exe + values[:gpg_exe] = gpg_exe end opts.on('-h', '--help', I18n.t('option.help')) do @@ -43,19 +44,20 @@ OptionParser.new do |opts| end opts.on('-i', '--init GPG_KEY', I18n.t('option.init')) do |gpg_key| - options[:init] = gpg_key + options[:init] = true + values[:gpg_key] = gpg_key end opts.on('-k', '--key GPG_KEY', I18n.t('option.gpg_key')) do |gpg_key| - options[:gpg_key] = gpg_key + values[:gpg_key] = gpg_key end opts.on('-l', '--lang LANG', I18n.t('option.lang')) do |lang| - options[:lang] = lang + values[:lang] = lang end opts.on('-w', '--wallet-dir PATH', I18n.t('option.wallet_dir')) do |wallet_dir| - options[:wallet_dir] = wallet_dir + values[:wallet_dir] = wallet_dir end end.parse! @@ -63,9 +65,10 @@ config = MPW::Config.new(options[:config]) cli = MPW::Cli.new(config, nil) if not options[:init].nil? - cli.setup(options) + cli.get_wallet + cli.setup(values) cli.setup_gpg_key(options[:init]) cli.setup_wallet_config else - cli.set_config(options) + cli.set_config(values) end diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 464d098..b0161a1 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -32,7 +32,7 @@ class Cli # Constructor # @args: config -> the config # sync -> boolean for sync or not - def initialize(config,sync=true) + def initialize(config, sync=true) @config = config @sync = sync end @@ -54,7 +54,7 @@ class Cli end # Create a new config file - # @args: language -> the software language + # @args: options -> set param def setup(options) @config.is_valid? @@ -75,6 +75,8 @@ class Cli # Setup a new GPG key # @args: gpg_key -> the key name def setup_gpg_key(gpg_key) + return if @config.check_gpg_key? + password = ask(I18n.t('form.setup_gpg_key.password')) {|q| q.echo = false} confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false} @@ -320,10 +322,7 @@ class Cli if wallet.to_s.empty? wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") - case wallets.length - when 0 - puts I18n.t('display.nothing') - when 1 + if wallets.length == 1 @wallet_file = wallets[0] else @wallet_file = "#{@config.wallet_dir}/default.mpw"