Class: Dmp::CLI

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

Overview

Command line interface for DMP

Instance Method Summary collapse

Instance Method Details

#aboutObject



64
65
66
67
68
69
70
71
72
# File 'lib/dmp/cli.rb', line 64

def about
  # Displays banner, version number and author
  puts Dmp::BANNER.bold.red
  puts 'version: '.bold + Dmp::VERSION.green
  puts 'author: '.bold + '@__franccesco'.green
  puts 'homepage: '.bold + 'https://github.com/franccesco/dmp'.green
  puts 'learn more: '.bold + 'https://codingdose.info'.green
  puts # extra line, somehow I like them.
end

#check_passObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/dmp/cli.rb', line 52

def check_pass
  puts 'Enter your password, press ENTER when you\'re done.'
  password = ask('Password (hidden):'.yellow, echo: false)
  vuln_count = Dmp.check_pwned(password)
  if vuln_count
    puts " Your password appears in #{vuln_count} data sets!".red.bold
  else
    puts " Your password/passphrase is safe to use.".green.bold
  end
end

#gen_pass(pass_length = 7) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dmp/cli.rb', line 19

def gen_pass(pass_length = 7)
  # Generate colored passphrase
  passphrase = Dmp.gen_passphrase(pass_length.to_i)

  # if flag clipboard is 'true' then copy passphrase to clipboard
  if options[:clipboard]
    Clipboard.copy(passphrase.join(' '))
  end

  # if flag hibp is 'true' then alert the user
  if options[:hibp]
    vuln_count = Dmp.check_pwned(passphrase)
  end

  # colors array will be used to pick a randomized sample
  # removing black cause it looks ugly in terminals
  colors = String.colors
  colors.delete(:black)

  passphrase.map! do |phrase|
    rand_color = colors.sample
    phrase.colorize(rand_color)
  end
  puts '- Passphrase: '.bold + passphrase.join(' ')
  puts '- Copied to clipboard.'.bold.green if options[:clipboard]
  if vuln_count
    puts "- WARNING: Passphrase vulnerable #{vuln_count} times!".red.bold
  elsif options[:hibp]
    puts '- Password is safe to use.'.green.bold
  end
end