Class: PolypassCLI

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

Overview

Thor powered command-line interface

Instance Method Summary collapse

Instance Method Details

#create(type) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/polypass/cli.rb', line 28

def create(type)
  length = options[:length].nil? ? 32 : options[:length]
  output = options[:output].nil? ? 'stdout' : options[:output]

  unless ['stdout', 'json', 'yaml'].include?(output)
    raise ArgumentError,
          output + ' is not a valid output type. ' +
          'Available types include: stdout, json, yaml'
  end

  case type
  when 'alphanum'
    puts 'Generating a new secure random alphanumeric password:'
    puts Polypass::AlphaNumeric.new(length, output).create
  when 'alphasym'
    puts 'Generating a new secure random alphanumeric symbol password:'
    puts Polypass::AlphaSymbol.new(length, output).create
  when 'natural'
    length = options[:length].nil? ? 4 : options[:length]
    puts 'Generating a new secure random natural language password:'
    puts Polypass::NaturalLanguage.new(length, output).create
  else
    raise ArgumentError,
          type + ' is not a valid password type. Avaiable types include: alphanum, alphasym, natural'
  end
end

#versionObject



9
10
11
# File 'lib/polypass/cli.rb', line 9

def version
  puts 'polypass ' + Polypass::VERSION
end