Sha256: a6035b5376ee1dc71fbb3812ab60482dcf49167294d2cc3365641142cf28febc

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'thor'
require 'dmp'
require 'colorize'
require 'clipboard'

module Dmp
  # Command line interface for DMP
  class CLI < Thor
    default_task :gen_pass
    desc 'gen [length]', 'Generate a passphrase of the desired length.'
    method_option :clipboard,
                  aliases: '-c',
                  type: :boolean,
                  desc: 'Copy passphrase to clipboard.'
    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

      # 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
      print '[*] Passphrase: '.bold + passphrase.join(' ')
    end

    desc 'about', 'Displays version number and information'
    def about
      # Displays banner, version number and author
      banner = '''
  ____    __  __   ____  
 |  _ \  |  \/  | |  _ \ 
 | | | | | |\/| | | |_) |
 | |_| | | |  | | |  __/ 
 |____/  |_|  |_| |_|
               '''.bold.red
    puts banner
    puts ' version: '.bold + '0.1.0'.white
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dmp-0.1.1 lib/dmp/cli.rb
dmp-0.1.0 lib/dmp/cli.rb