mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
111 lines
2.3 KiB
Ruby
Executable file
111 lines
2.3 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}/lib/Cli.rb"
|
|
|
|
options = {}
|
|
options[:force] = false
|
|
options[:format] = false
|
|
options[:group] = nil
|
|
|
|
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[:type] = 'all'
|
|
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("-g", "--group GROUP", "Select a group") do |group|
|
|
options[:group] = group
|
|
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("-F", "--format", "Change the display format by an alternatif") do |b|
|
|
options[:format] = 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?
|
|
cli.display(options[:display], options[:group], options[:type], options[:format])
|
|
|
|
# Remove an item
|
|
elsif not options[:remove].nil?
|
|
cli.remove(options[:remove], options[:force])
|
|
|
|
# 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], options[:force])
|
|
|
|
# Interactive mode
|
|
else
|
|
cli.interactive
|
|
end
|
|
|
|
exit 0
|
|
|