class Senha::CLI::Application
The Application
class is responsible for the
Public Class Methods
new()
click to toggle source
Creates a new instance of the Application
Class
@return [Application] New instance
# File lib/senha/cli/application.rb, line 36 def initialize end
Public Instance Methods
parse_arguments(args)
click to toggle source
Parses the command line arguments
# File lib/senha/cli/application.rb, line 40 def parse_arguments (args) begin options = {} options[:length] = Senha::DEFAULT_LENGTH options[:count] = 1 opts = OptionParser.new do |opt| opt.banner = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.hammackj.com\n\n" opt.banner << "Usage: #{APP_NAME} <options>" opt.separator('') opt.separator("Password Options") opt.on("-n", "--numbers", "Use digits [0-9] in the password generation") do |n| options[:numbers] = n end opt.on("-p", "--punctuation", "Use punctuation in the password generation") do |p| options[:punct] = p end opt.on("-s", "--symbols", "Use symbols in the password generation") do |s| options[:symbols] = s end opt.on("-l", "--lowercase", "Use lowercase [a-z] in the password generation") do |l| options[:lowercase] = l end opt.on("-u", "--uppercase", "Use uppercase [A-Z] in the password generation") do |u| options[:uppercase] = u end opt.on("-a", "--all-characters", "Use all available character sets for password generationA") do |a| options[:all] = a end opt.separator '' opt.separator 'Other Options' opt.on("--count COUNT", Integer, "Number of passwords to generate, default is 1") do |count| options[:count] = count#.to_i end opt.on("--length LENGTH", Integer, "Use uppercase in the password generation, default is 10") do |length| options[:length] = length#.to_i end opt.on_tail('-v', '--version', "Shows application version information") do puts "#{APP_NAME} - #{VERSION}" exit end opt.on_tail("-?", "--help", "Show this message") do puts opt.to_s + "\n" exit end end if args.length != 0 opts.parse! args else puts opts.to_s + "\n" exit end options rescue OptionParser::MissingArgument => m puts opts.to_s + "\n" exit rescue OptionParser::InvalidOption => i puts opts.to_s + "\n" exit end end
run(args)
click to toggle source
Main body of the Application
class
# File lib/senha/cli/application.rb, line 117 def run(args) options = parse_arguments(args) if options != nil gen = Senha::Base::Generator.new(options) options[:count].times do puts gen.password(options[:length]) end end end