1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-12-04 02:03:03 +00:00
mpw/mpw

112 lines
2.3 KiB
Text
Raw Normal View History

2013-07-16 17:42:49 +00: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 19:56:45 +00:00
require 'pathname'
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
2013-07-18 20:12:45 +00:00
require "#{APP_ROOT}/Cli.rb"
2013-07-16 17:57:48 +00:00
2013-07-16 17:42:49 +00:00
options = {}
OptionParser.new do |opts|
2013-07-17 20:31:28 +00:00
opts.banner = "Usage: mpw [options]"
2013-07-16 17:42:49 +00: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|
options[:showall] = true
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
opts.on("-a", "--add", "Add an items") do |b|
options[:add] = true
end
2013-07-18 20:16:53 +00:00
opts.on("-S", "--setup", "Setup the config file") do |b|
options[:setup] = true
end
2013-07-17 20:31:28 +00:00
opts.on("-p", "--protocol PROTOCOL", "Select a protocol") do |type|
2013-07-16 17:42:49 +00:00
options[:type] = type
end
2013-07-25 17:51:43 +00: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 20:31:28 +00:00
opts.on("-f", "--force", "Force an action") do |b|
options[:force] = true
end
2013-07-16 17:42:49 +00:00
opts.on("-h", "--help", "Show this message") do |b|
puts opts
exit 0
end
end.parse!
2013-07-17 20:31:28 +00:00
cli = Cli.new()
2013-07-16 17:42:49 +00:00
# Display the item's informations
2013-07-18 20:16:53 +00:00
if not options[:setup].nil?
cli.setup()
elsif not options[:display].nil?
2013-07-16 17:42:49 +00:00
if not options[:type].nil?
2013-07-17 20:31:28 +00:00
cli.display(options[:display], options[:type])
2013-07-16 17:42:49 +00:00
elsif not options[:showall].nil?
2013-07-17 20:31:28 +00:00
cli.display(options[:display], 'all')
2013-07-16 17:42:49 +00:00
else
2013-07-17 20:31:28 +00:00
cli.display(options[:display])
2013-07-16 17:42:49 +00:00
end
# Remove an item
elsif not options[:remove].nil?
if not options[:force].nil?
cli.remove(options[:remove], options[:force])
else
cli.remove(options[:remove])
end
2013-07-16 17:42:49 +00:00
# Update an item
elsif not options[:update].nil?
2013-07-17 20:31:28 +00:00
cli.update(options[:update])
2013-07-16 17:42:49 +00:00
# Add a new item
elsif not options[:add].nil?
2013-07-17 20:31:28 +00:00
cli.add()
2013-07-16 17:42:49 +00:00
2013-07-25 17:51:43 +00:00
# Export
elsif not options[:export].nil?
cli.export(options[:export])
# Add a new item
elsif not options[:import].nil?
2013-08-26 20:19:37 +00:00
if not options[:force].nil?
cli.import(options[:import], options[:force])
else
cli.import(options[:import])
end
2013-07-16 17:42:49 +00:00
else
puts "For help add option -h or --help"
end
exit 0