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



70
71
72
73
74
75
76
77
# File 'lib/dmp/cli.rb', line 70

def about
  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



57
58
59
60
61
62
63
64
65
66
# File 'lib/dmp/cli.rb', line 57

def check_pass
  puts "Enter your password, press ENTER when you're done."
  password = ask('Password (hidden):'.yellow, echo: false)
  (puts "Aborted.".red.bold; exit) if password.empty?

  dataset_count = Dmp.check_pwned(password)
  vuln_msg = "Your password appears in #{dataset_count} datasets!".red.bold
  safe_msg = "Your password was not found in a dataset.".green.bold
  puts dataset_count ? vuln_msg : safe_msg
end

#gen_pass(pass_length = 7) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dmp/cli.rb', line 29

def gen_pass(pass_length = 7)
  new_passphrase = Dmp.gen_passphrase(pass_length.to_i)
  Clipboard.copy(new_passphrase.join(' ')) if options[:clipboard]
  dataset_count = Dmp.check_pwned(new_passphrase) if options[:hibp]

  colors = String.colors
  colors.delete(:black) # black color looks ugly in the terminal
  new_passphrase.map! do |phrase|
    random_color = colors.sample
    phrase.colorize(random_color)
  end

  copy_msg = '- Copied to clipboard.'.bold.green
  vuln_pass_msg = "- WARNING: Passphrase appears in #{dataset_count} datasets!".red.bold
  safe_pass_msg = '- Password was not found in a dataset.'.green.bold

  puts '- Passphrase: '.bold + new_passphrase.join(' ')
  puts copy_msg if options[:clipboard]
  puts dataset_count ? vuln_pass_msg : safe_pass_msg if options[:hibp]
end