Class: Shhh::App::Commands::ShowLanguageExamples

Inherits:
Command
  • Object
show all
Defined in:
lib/shhh/app/commands/show_language_examples.rb

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Shhh::App::Commands::Command

Instance Method Details

#example(comment: nil, command: nil, echo: nil, result: nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/shhh/app/commands/show_language_examples.rb', line 57

def example(comment: nil, command: nil, echo: nil, result: nil)
  @dict   ||= ::Shhh::App::NLP::Constants::DICTIONARY.to_a.flatten!
  _command = command.split(' ').map do |w|
    _w = w.to_sym
    if w == 'shhh'
      w.italic.yellow
    elsif ::Shhh::App::NLP::Constants::STRIPPED.include?(_w)
      w.italic.red
    elsif @dict.include?(_w)
      w.blue
    else
      w
    end
  end.join(' ') if command
  out     = []
  out << "# #{comment}".white.dark.italic if comment
  out << "#{_command}" if command
  out << "#{echo}" if echo
  out << "#{result}" if result
  out << (' '*80).dark
end

#executeObject



13
14
15
16
17
18
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
50
51
52
53
54
55
# File 'lib/shhh/app/commands/show_language_examples.rb', line 13

def execute
  output = []

  output << Shhh::App::NLP::Base.usage

  output << example(comment: 'generate a new private key and copy to the clipboard but do not print to terminal',
                    command: 'shhh create new key to clipboard quietly'
  )

  output << example(comment: 'generate and save to a file a password-protected key, silently',
                    command: 'shhh create a secure key and save it to "my.key"',
  )

  output << example(comment: 'encrypt a plain text string with a key, and save the output to a file',
                    command: 'shhh encrypt string "secret string" using $(cat my.key) save to file.enc')

  output << example(comment: 'decrypt a previously encrypted string:',
                    command: 'shhh decrypt string $ENC using $(cat my.key)')

  output << example(comment: 'encrypt "file.txt" with key from my.key and save it to file.enc',
                    command: 'shhh encrypt file file.txt with key from my.key and save it to file.enc')

  output << example(comment: 'decrypt an encrypted file and print it to STDOUT:',
                    command: 'shhh decrypt file file.enc with key from "my.key"')

  output << example(comment: 'edit an encrypted file in $EDITOR, ask for key, and create a backup upon save',
                    command: 'shhh edit file file.enc ask for a key and make a backup',
  )

  if Shhh::App.is_osx?
    output << example(comment: 'generate a new password-encrypted key, save it to your Keychain:',
                      command: 'shhh create a new protected key store in keychain "my-keychain-key"')

    output << example(comment: 'print the key stored in the keychain item "my-keychain-key"',
                      command: 'shhh print keychain "my-keychain-key"')

    output << example(comment: 'use the new key to encrypt a file:',
                      command: 'shhh encrypt with keychain "my-keychain-key" file "password.txt" and write to "passwords.enc"')

  end

  output.flatten.compact.join("\n")
end