1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-26 23:33:03 +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"
group: "Search the items with specified group"
add: "Add an item"
config: "Specify the configuration file to use"
setup: "Create a new configuration file"
protocol: "Select the items with the specified protocol"
export: "Export all items in a CSV file"

View file

@ -28,6 +28,7 @@ fr:
remove: "Supprime un élément"
group: "Recherche les éléments appartenant au groupe spécifié"
add: "Ajoute un élément"
config: "Spécifie le fichier de configuration à utiliser"
setup: "Création d'un nouveau fichier de configuration"
protocol: "Sélectionne les éléments ayant le protocole spécifié"
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
# Constructor
def initialize(lang)
@m = MPW.new()
def initialize(lang, config_file=nil)
@m = MPW.new(config_file)
if not @m.checkconfig()
self.setup(lang)

View file

@ -25,9 +25,13 @@ class MPW
attr_accessor :timeout_pwd
# Constructor
def initialize()
def initialize(file_config=nil)
@error_msg = nil
@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
# Create a new config file

7
mpw
View file

@ -25,6 +25,7 @@ options = {}
options[:force] = false
options[:format] = false
options[:group] = nil
options[:config] = nil
OptionParser.new do |opts|
opts.banner = "#{I18n.t('cli.option.usage')}: mpw [options]"
@ -54,6 +55,10 @@ OptionParser.new do |opts|
options[:add] = true
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|
options[:setup] = true
end
@ -85,7 +90,7 @@ OptionParser.new do |opts|
end.parse!
cli = Cli.new(lang)
cli = Cli.new(lang, options[:config])
# Display the item's informations
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.locale = lang.to_sym
cli = CliSSH.new(lang)
options = {}
OptionParser.new do |opts|
opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
opts.on("-l", "--login LOGIN", I18n.t('ssh.option.login')) do |login|
cli.login = login
options[:login] = login
end
opts.on("-s", "--server SERVER", I18n.t('ssh.option.server')) do |server|
cli.server = server
options[:server] = server
end
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
opts.on("-h", "--help", I18n.t('ssh.option.help')) do |b|
@ -44,7 +47,12 @@ OptionParser.new do |opts|
end
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
puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"