Class: Senha::CLI::Application
- Inherits:
-
Object
- Object
- Senha::CLI::Application
- Defined in:
- lib/senha/cli/application.rb
Overview
The Application class is responsible for the
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
Creates a new instance of the Application Class.
-
#parse_arguments(args) ⇒ Object
Parses the command line arguments.
-
#run(args) ⇒ Object
Main body of the Application class.
Constructor Details
#initialize ⇒ Application
Creates a new instance of the Application Class
36 37 |
# File 'lib/senha/cli/application.rb', line 36 def initialize end |
Instance Method Details
#parse_arguments(args) ⇒ Object
Parses the command line arguments
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/senha/cli/application.rb', line 40 def parse_arguments (args) begin = {} [:length] = Senha::DEFAULT_LENGTH [:count] = 1 opts = OptionParser.new do |opt| opt. = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.hammackj.com\n\n" opt. << "Usage: #{APP_NAME} <options>" opt.separator('') opt.separator("Password Options") opt.on("-n", "--numbers", "Use digits [0-9] in the password generation") do |n| [:numbers] = n end opt.on("-p", "--punctuation", "Use punctuation in the password generation") do |p| [:punct] = p end opt.on("-s", "--symbols", "Use symbols in the password generation") do |s| [:symbols] = s end opt.on("-l", "--lowercase", "Use lowercase [a-z] in the password generation") do |l| [:lowercase] = l end opt.on("-u", "--uppercase", "Use uppercase [A-Z] in the password generation") do |u| [:uppercase] = u end opt.on("-a", "--all-characters", "Use all available character sets for password generationA") do |a| [:all] = a end opt.separator '' opt.separator 'Other Options' opt.on("--count COUNT", Integer, "Number of passwords to generate, default is 1") do |count| [:count] = count#.to_i end opt.on("--length LENGTH", Integer, "Use uppercase in the password generation, default is 10") do |length| [: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 rescue OptionParser::MissingArgument => m puts opts.to_s + "\n" exit rescue OptionParser::InvalidOption => i puts opts.to_s + "\n" exit end end |
#run(args) ⇒ Object
Main body of the Application class
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/senha/cli/application.rb', line 117 def run(args) = parse_arguments(args) if != nil gen = Senha::Base::Generator.new() [:count].times do puts gen.password([:length]) end end end |