twik-ruby/lib/twik/cli/options.rb

57 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2014-10-21 09:23:37 +02:00
require 'optparse'
class Twik
class Cli
class Options
def self.parse(args)
options = {}
parser = ::OptionParser.new do |opts|
opts.banner = 'Usage: twik [options] tag'
opts.separator ''
opts.separator 'Specific options:'
2014-10-22 10:41:53 +02:00
opts.on('-l', '--length LENGTH', 'length of generated password (4-26)') do |length|
2014-10-21 09:23:37 +02:00
options['length'] = length.to_i
end
2014-10-22 10:41:53 +02:00
opts.on('-p', '--profile PROFILE', "profile to use") do |profile|
2014-10-21 09:23:37 +02:00
options['profile'] = profile
end
opts.on('-t', '--type TYPE', Twik::TYPE,
2014-10-22 10:41:53 +02:00
"type of password:", " #{Twik::TYPE.join(', ')}") do |type|
2014-10-21 09:23:37 +02:00
options['type'] = type.to_sym
end
opts.separator ''
opts.separator 'Common options:'
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
opts.on_tail('--version', 'Show version') do
puts "#{opts.program_name} #{Immoconv::VERSION}"
exit
end
end
begin
parser.parse!(args)
rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e
puts e.message
puts parser
exit
end
options['tag'] = args.shift
options
end
end
end
end