1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-20 01:50:04 +00:00

config: fix init with existing gpg key

This commit is contained in:
Adrien Waksberg 2016-10-20 21:25:43 +02:00
parent 337f1e2314
commit 7b301519b6
2 changed files with 15 additions and 13 deletions

View file

@ -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

View file

@ -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"