Module: Trustworthy::CLI::Command

Included in:
Trustworthy::CLI, AddKey, Decrypt, Encrypt, Init, Passwd
Defined in:
lib/trustworthy/cli/command.rb

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



4
5
6
# File 'lib/trustworthy/cli/command.rb', line 4

def default_options
  {config_file: 'trustworthy.yml'}
end

#parse_options(command, args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trustworthy/cli/command.rb', line 8

def parse_options(command, args)
  options = default_options
  @parser = OptionParser.new do |opts|
    opts.banner = "#{Trustworthy::CLI.banner}\n\nUsage: trustworthy #{command} [options]\n"
    opts.on('-c', '--config FILE', 'Configuration file to use (default: trustworthy.yml)') do |file|
      options[:config_file] = file
    end

    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end

    if block_given?
      yield opts, options
    end
  end
  @parser.parse!(args)
  options
end


29
30
31
# File 'lib/trustworthy/cli/command.rb', line 29

def print_help
  puts @parser if @parser
end

#say(message) ⇒ Object



33
34
35
# File 'lib/trustworthy/cli/command.rb', line 33

def say(message)
  $terminal.say(message)
end