Class: Trustworthy::CLI

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/trustworthy/cli.rb,
lib/trustworthy/cli/init.rb,
lib/trustworthy/cli/crypt.rb,
lib/trustworthy/cli/passwd.rb,
lib/trustworthy/cli/add_key.rb,
lib/trustworthy/cli/command.rb,
lib/trustworthy/cli/decrypt.rb,
lib/trustworthy/cli/encrypt.rb

Defined Under Namespace

Modules: Command, Crypt Classes: AddKey, Decrypt, Encrypt, Init, Passwd

Constant Summary collapse

Commands =
{
  'add-key' => Trustworthy::CLI::AddKey,
  'init'    => Trustworthy::CLI::Init,
  'decrypt' => Trustworthy::CLI::Decrypt,
  'encrypt' => Trustworthy::CLI::Encrypt,
  'passwd'  => Trustworthy::CLI::Passwd
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

#default_options, #parse_options, #print_help, #say

Class Method Details



25
26
27
# File 'lib/trustworthy/cli.rb', line 25

def self.banner
  "Trustworthy CLI v#{Trustworthy::VERSION}"
end

Instance Method Details

#_print_helpObject



39
40
41
42
43
44
45
46
# File 'lib/trustworthy/cli.rb', line 39

def _print_help
  say("#{Trustworthy::CLI.banner}\n\n")
  say('Commands:')
  Commands.each do |name, klass|
    say(format('  %-8s %s', name, klass.description))
  end
  say("\nSee 'trustworthy <command> --help' for more information on a specific command")
end

#run(args) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/trustworthy/cli.rb', line 29

def run(args)
  command = args.shift
  if Commands.key?(command)
    klass = Commands[command]
    klass.new.run(args)
  else
    _print_help
  end
end