1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-20 21:34:35 +00:00
mpw/mpw
2013-08-06 21:42:47 +02:00

108 lines
2.2 KiB
Ruby
Executable file

#!/usr/bin/ruby
# author: nishiki
# mail: nishiki@yaegashi.fr
# info: a simple script who manage your passwords
require 'rubygems'
require 'optparse'
require 'pathname'
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
require "#{APP_ROOT}/Cli.rb"
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: mpw [options]"
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
opts.on("-S", "--setup", "Setup the config file") do |b|
options[:setup] = true
end
opts.on("-p", "--protocol PROTOCOL", "Select a protocol") do |type|
options[:type] = type
end
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
opts.on("-f", "--force", "Force an action") do |b|
options[:force] = true
end
opts.on("-h", "--help", "Show this message") do |b|
puts opts
exit 0
end
end.parse!
cli = Cli.new()
# Display the item's informations
if not options[:setup].nil?
cli.setup()
elsif not options[:display].nil?
if not options[:type].nil?
cli.display(options[:display], options[:type])
elsif not options[:showall].nil?
cli.display(options[:display], 'all')
else
cli.display(options[:display])
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
# Update an item
elsif not options[:update].nil?
cli.update(options[:update])
# Add a new item
elsif not options[:add].nil?
cli.add()
# Export
elsif not options[:export].nil?
cli.export(options[:export])
# Add a new item
elsif not options[:import].nil?
cli.import(options[:import])
else
puts "For help add option -h or --help"
end
exit 0