1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-12-03 17:53:04 +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-09-04 17:48:06 +00:00
require "#{APP_ROOT}/lib/Cli.rb"
2013-07-16 17:57:48 +00:00
2013-07-16 17:42:49 +00:00
options = {}
options[:force] = false
options[:format] = false
2013-09-09 19:48:42 +00:00
options[:group] = nil
2013-07-16 17:42:49 +00:00
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[:type] = 'all'
2013-07-16 17:42:49 +00: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 19:48:42 +00:00
opts.on("-g", "--group GROUP", "Select a group") do |group|
options[:group] = group
end
2013-07-16 17:42:49 +00:00
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
opts.on("-F", "--format", "Change the display format by an alternatif") do |b|
options[:format] = 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-09-09 19:48:42 +00:00
cli.display(options[:display], options[:group], options[:type], options[:format])
2013-07-16 17:42:49 +00:00
# Remove an item
elsif not options[:remove].nil?
cli.remove(options[:remove], options[:force])
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?
cli.import(options[:import], options[:force])
2013-07-16 17:42:49 +00:00
2013-09-08 15:56:10 +00:00
# Interactive mode
else
cli.interactive
2013-07-16 17:42:49 +00:00
end
exit 0