1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-26 23:33:03 +00:00

feat: add print configuration

This commit is contained in:
Adrien Waksberg 2017-04-09 10:08:25 +02:00
parent b65595d0b7
commit 3f9d7eff33
4 changed files with 42 additions and 12 deletions

View file

@ -112,5 +112,9 @@ if options.key?(:init)
cli.setup_wallet_config cli.setup_wallet_config
else else
cli.load_config cli.load_config
if values.empty?
cli.list_config
else
cli.set_config(values) cli.set_config(values)
end end
end

View file

@ -159,6 +159,7 @@ en:
display: display:
comment: "Comment" comment: "Comment"
config: "Configuration"
error: "ERROR" error: "ERROR"
keys: "GPG keys" keys: "GPG keys"
gpg_password: "GPG passphrase: " gpg_password: "GPG passphrase: "

View file

@ -159,6 +159,7 @@ fr:
display: display:
comment: "Commentaire" comment: "Commentaire"
config: "Configuration"
error: "ERREUR" error: "ERREUR"
keys: "Clés GPG" keys: "Clés GPG"
gpg_password: "Mot de passe GPG: " gpg_password: "Mot de passe GPG: "

View file

@ -100,6 +100,21 @@ module MPW
table_list('keys', @mpw.list_keys) table_list('keys', @mpw.list_keys)
end end
# List config
def list_config
config = {
'lang' => @config.lang,
'gpg_key' => @config.gpg_key,
'config_dir' => @config.config_dir,
'pinmode' => @config.pinmode,
'gpg_exe' => @config.gpg_exe
}
@config.password.each { |k, v| config["password_#{k}"] = v }
table_list('config', config)
end
# Load config # Load config
def load_config def load_config
@config.load_config @config.load_config
@ -122,31 +137,40 @@ module MPW
end end
# Format list on a table # Format list on a table
# @args: title -> the name of table
# list -> array or hash
def table_list(title, list) def table_list(title, list)
i = 1 length = { k: 0, v: 0 }
length = 0
list.each do |item| if list.is_a?(Array)
length = item.length if length < item.length i = 0
list = list.map do |item|
i += 1
[i, item]
end.to_h
end
list.each do |k, v|
length[:k] = k.to_s.length if length[:k] < k.to_s.length
length[:v] = v.to_s.length if length[:v] < v.to_s.length
end end
length += 7
puts "\n#{I18n.t("display.#{title}")}".red puts "\n#{I18n.t("display.#{title}")}".red
print ' ' print ' '
length.times { print '=' } (length[:k] + length[:v] + 5).times { print '=' }
print "\n" print "\n"
list.each do |item| list.each do |k, v|
print " #{i}".cyan print " #{k}".cyan
(3 - i.to_s.length).times { print ' ' } (length[:k] - k.to_s.length + 1).times { print ' ' }
puts "| #{item}" puts "| #{v}"
i += 1
end end
print "\n" print "\n"
end end
# Format items on a table # Format items on a table
# @args: items -> an aray items
def table_items(items = []) def table_items(items = [])
group = '.' group = '.'
i = 1 i = 1