Class: XKPassword::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/xkpassword/cli.rb

Overview

Command-line entrypoint for the xkpassword executable.

Constant Summary collapse

INFO_MESSAGE =
<<~TEXT.freeze
  #{Artii::Base.new(font: 'standard').asciify('XKPassword')}
  by Ziyan Junaideen

  How many times have you changed your password just because you forgot it?
  Well, you are not alone. In todays security requirements, passwords need
  to be secure and difficult to break. Passwords need to be secure, sure,
  but they can also be easy to remember. Follow up this XKCD article for more
  information - http://xkcd.com/936/

  This does exactly what the picture predicts. You can use this in your Ruby
  applications (Ex: Rails, Sinatra) or standalone if you install the gem (as
  you have done here).

  Wish you all the best keeping things secure.

  Ziyan Junaideen
  ziyan@jdeen.com
TEXT

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV, stdout: $stdout, stderr: $stderr, env: ENV) ⇒ CLI

Returns a new instance of CLI.



32
33
34
35
36
37
38
# File 'lib/xkpassword/cli.rb', line 32

def initialize(argv = ARGV, stdout: $stdout, stderr: $stderr, env: ENV)
  @argv = argv.dup
  @stdout = stdout
  @stderr = stderr
  @config_file = XKPassword::ConfigFile.new(XKPassword::ConfigFile.default_path(env))
  @options = {}
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xkpassword/cli.rb', line 40

def run
  option_parser.parse!(@argv)

  return initialize_config if @options[:init]
  return write_special_output if special_output?

  options = @config_file.load.merge(@options)
  write_line(XKPassword.generate(options))
rescue OptionParser::ParseError, XKPassword::ConfigFile::Error, ArgumentError => e
  @stderr.puts(e.message)
  1
end