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

123 lines
2.5 KiB
Text
Raw Normal View History

2013-07-16 19:42:49 +02:00
#!/usr/bin/ruby
# author: nishiki
# mail: nishiki@yaegashi.fr
# info: a simple script who manage your passwords
require 'rubygems'
require 'optparse'
2013-07-18 21:56:45 +02:00
require 'pathname'
2013-12-25 18:51:41 +01:00
require 'locale'
require 'i18n'
2013-07-18 21:56:45 +02:00
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
2013-09-04 19:48:06 +02:00
require "#{APP_ROOT}/lib/Cli.rb"
2013-07-16 19:57:48 +02:00
2013-12-25 18:51:41 +01:00
2013-12-26 10:47:54 +01:00
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
2013-12-25 18:51:41 +01:00
if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml")
2013-12-26 10:47:54 +01:00
lang = 'en'
2013-12-25 18:51:41 +01:00
end
I18n.load_path = Dir["#{APP_ROOT}/i18n/#{lang}.yml"]
I18n.locale = lang.to_sym
2013-07-16 19:42:49 +02:00
options = {}
options[:force] = false
options[:format] = false
2013-09-09 21:48:42 +02:00
options[:group] = nil
2013-07-16 19:42:49 +02:00
OptionParser.new do |opts|
2013-07-17 22:31:28 +02:00
opts.banner = "Usage: mpw [options]"
2013-07-16 19:42:49 +02:00
opts.on("-d", "--display [SEARCH]", "Display items") do |search|
search.nil? ? (options[:display] = '') : (options[:display] = search)
end
opts.on("-A", "--show-all", "Show all items") do |b|
2013-09-19 22:18:59 +02:00
options[:type] = nil
2013-07-16 19:42:49 +02:00
options[:display] = ""
end
opts.on("-u", "--update ID", "Update an items") do |id|
options[:update] = id
end
opts.on("-r", "--remove ID", "Remove an items") do |id|
options[:remove] = id
end
2013-09-09 21:48:42 +02:00
opts.on("-g", "--group GROUP", "Select a group") do |group|
options[:group] = group
end
2013-07-16 19:42:49 +02:00
opts.on("-a", "--add", "Add an items") do |b|
options[:add] = true
end
2013-07-18 22:16:53 +02:00
opts.on("-S", "--setup", "Setup the config file") do |b|
options[:setup] = true
end
2013-07-17 22:31:28 +02:00
opts.on("-p", "--protocol PROTOCOL", "Select a protocol") do |type|
2013-07-16 19:42:49 +02:00
options[:type] = type
end
2013-07-25 19:51:43 +02:00
opts.on("-e", "--export FILE", "Export to csv file") do |file|
options[:export] = file
end
opts.on("-i", "--import FILE", "Import from csv file") do |file|
options[:import] = file
end
2013-07-17 22:31:28 +02:00
opts.on("-f", "--force", "Force an action") do |b|
options[:force] = true
end
opts.on("-F", "--format", "Change the display format by an alternatif") do |b|
options[:format] = true
end
2013-07-16 19:42:49 +02:00
opts.on("-h", "--help", "Show this message") do |b|
puts opts
exit 0
end
end.parse!
2013-12-25 18:51:41 +01:00
cli = Cli.new(lang)
2013-07-16 19:42:49 +02:00
# Display the item's informations
2013-07-18 22:16:53 +02:00
if not options[:setup].nil?
cli.setup()
elsif not options[:display].nil?
2013-09-09 21:48:42 +02:00
cli.display(options[:display], options[:group], options[:type], options[:format])
2013-07-16 19:42:49 +02:00
# Remove an item
elsif not options[:remove].nil?
cli.remove(options[:remove], options[:force])
2013-07-16 19:42:49 +02:00
# Update an item
elsif not options[:update].nil?
2013-07-17 22:31:28 +02:00
cli.update(options[:update])
2013-07-16 19:42:49 +02:00
# Add a new item
elsif not options[:add].nil?
2013-07-17 22:31:28 +02:00
cli.add()
2013-07-16 19:42:49 +02:00
2013-07-25 19:51:43 +02:00
# Export
elsif not options[:export].nil?
cli.export(options[:export])
# Add a new item
elsif not options[:import].nil?
cli.import(options[:import], options[:force])
2013-07-16 19:42:49 +02:00
2013-09-08 17:56:10 +02:00
# Interactive mode
else
cli.interactive
2013-07-16 19:42:49 +02:00
end
exit 0