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

85 lines
1.7 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'
require './manage-password.rb'
2013-07-16 20:36:41 +00:00
require './cli.rb'
2013-07-16 17:57:48 +00:00
2013-07-16 17:42:49 +00:00
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: manage-password.rb [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("-t", "--type TYPE", "select an type") do |type|
options[:type] = type
end
opts.on("-h", "--help", "Show this message") do |b|
puts opts
exit 0
end
end.parse!
2013-07-16 20:36:41 +00:00
cli = Cli.new
manage = ManagePasswd.new(cli.key, cli.file_gpg, cli.file_pwd)
2013-07-16 17:42:49 +00:00
# Display the item's informations
if not options[:display].nil?
if not options[:type].nil?
manage.display(options[:display], options[:type])
elsif not options[:showall].nil?
manage.display(options[:display], 'all')
else
manage.display(options[:display])
end
# Remove an item
elsif not options[:remove].nil?
manage.remove(options[:remove])
manage.encrypt()
# Update an item
elsif not options[:update].nil?
manage.update(options[:update])
manage.encrypt()
# Connect to ssh
elsif not options[:ssh].nil?
manage.ssh(options[:ssh])
# Add a new item
elsif not options[:add].nil?
manage.add()
manage.encrypt()
else
puts "For help add option -h or --help"
end
exit 0