1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-30 08:53:05 +00:00

add option select config file (--config CONFIG)

This commit is contained in:
nishiki 2013-12-30 20:15:00 +01:00
parent 619d5afd8c
commit 745d3e82c5
6 changed files with 29 additions and 10 deletions

View file

@ -28,6 +28,7 @@ en:
remove: "Delete an item" remove: "Delete an item"
group: "Search the items with specified group" group: "Search the items with specified group"
add: "Add an item" add: "Add an item"
config: "Specify the configuration file to use"
setup: "Create a new configuration file" setup: "Create a new configuration file"
protocol: "Select the items with the specified protocol" protocol: "Select the items with the specified protocol"
export: "Export all items in a CSV file" export: "Export all items in a CSV file"

View file

@ -28,6 +28,7 @@ fr:
remove: "Supprime un élément" remove: "Supprime un élément"
group: "Recherche les éléments appartenant au groupe spécifié" group: "Recherche les éléments appartenant au groupe spécifié"
add: "Ajoute un élément" add: "Ajoute un élément"
config: "Spécifie le fichier de configuration à utiliser"
setup: "Création d'un nouveau fichier de configuration" setup: "Création d'un nouveau fichier de configuration"
protocol: "Sélectionne les éléments ayant le protocole spécifié" protocol: "Sélectionne les éléments ayant le protocole spécifié"
export: "Exporte tous les éléments dans un fichier au format CSV" export: "Exporte tous les éléments dans un fichier au format CSV"

View file

@ -14,8 +14,8 @@ require "#{APP_ROOT}/lib/MPW.rb"
class Cli class Cli
# Constructor # Constructor
def initialize(lang) def initialize(lang, config_file=nil)
@m = MPW.new() @m = MPW.new(config_file)
if not @m.checkconfig() if not @m.checkconfig()
self.setup(lang) self.setup(lang)

View file

@ -25,9 +25,13 @@ class MPW
attr_accessor :timeout_pwd attr_accessor :timeout_pwd
# Constructor # Constructor
def initialize() def initialize(file_config=nil)
@error_msg = nil
@file_config = "#{Dir.home()}/.mpw.cfg" @file_config = "#{Dir.home()}/.mpw.cfg"
@error_msg = nil
if !file_config.nil? && !file_config.empty? && File.exist?(file_config)
@file_config = file_config
end
end end
# Create a new config file # Create a new config file

7
mpw
View file

@ -25,6 +25,7 @@ options = {}
options[:force] = false options[:force] = false
options[:format] = false options[:format] = false
options[:group] = nil options[:group] = nil
options[:config] = nil
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('cli.option.usage')}: mpw [options]" opts.banner = "#{I18n.t('cli.option.usage')}: mpw [options]"
@ -54,6 +55,10 @@ OptionParser.new do |opts|
options[:add] = true options[:add] = true
end end
opts.on('-c', '--config CONFIG', I18n.t('cli.option.config')) do |config|
options[:config] = config
end
opts.on('-S', '--setup', I18n.t('cli.option.setup')) do |b| opts.on('-S', '--setup', I18n.t('cli.option.setup')) do |b|
options[:setup] = true options[:setup] = true
end end
@ -85,7 +90,7 @@ OptionParser.new do |opts|
end.parse! end.parse!
cli = Cli.new(lang) cli = Cli.new(lang, options[:config])
# Display the item's informations # Display the item's informations
if not options[:setup].nil? if not options[:setup].nil?

18
mpw-ssh
View file

@ -20,22 +20,25 @@ end
I18n.load_path = Dir["#{APP_ROOT}/i18n/#{lang}.yml"] I18n.load_path = Dir["#{APP_ROOT}/i18n/#{lang}.yml"]
I18n.locale = lang.to_sym I18n.locale = lang.to_sym
cli = CliSSH.new(lang)
options = {} options = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]" opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
opts.on("-l", "--login LOGIN", I18n.t('ssh.option.login')) do |login| opts.on("-l", "--login LOGIN", I18n.t('ssh.option.login')) do |login|
cli.login = login options[:login] = login
end end
opts.on("-s", "--server SERVER", I18n.t('ssh.option.server')) do |server| opts.on("-s", "--server SERVER", I18n.t('ssh.option.server')) do |server|
cli.server = server options[:server] = server
end end
opts.on("-p", "--port PORT", I18n.t('ssh.option.port')) do |port| opts.on("-p", "--port PORT", I18n.t('ssh.option.port')) do |port|
cli.port = port options[:port] = port
end
opts.on('-c', '--config CONFIG', I18n.t('cli.option.config')) do |config|
options[:config] = config
end end
opts.on("-h", "--help", I18n.t('ssh.option.help')) do |b| opts.on("-h", "--help", I18n.t('ssh.option.help')) do |b|
@ -44,7 +47,12 @@ OptionParser.new do |opts|
end end
end.parse! end.parse!
search = ARGV[0] cli = CliSSH.new(lang, options[:config])
cli.login = options[:login]
cli.server = options[:server]
cli.port = options[:port]
search = ARGV[0]
if ARGV.length < 1 if ARGV.length < 1
puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]" puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"