Module: Trustworthy::CLI::Crypt

Included in:
Decrypt, Encrypt
Defined in:
lib/trustworthy/cli/crypt.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



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

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#_check_options(args) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/trustworthy/cli/crypt.rb', line 34

def _check_options(args)
  options = parse_options(args)
  unless options.has_key?(:input_file) && options.has_key?(:output_file)
    print_help
    throw :error
  end
  options
end

#_commandObject



30
31
32
# File 'lib/trustworthy/cli/crypt.rb', line 30

def _command
  self.class._command
end

#parse_options(args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/trustworthy/cli/crypt.rb', line 8

def parse_options(args)
  super(_command, args) do |opts, options|
    opts.on('-i', '--input FILE', "File to #{_command}") do |file|
      options[:input_file] = file
    end

    opts.on('-o', '--output FILE', "File to write #{_command}ed contents to") do |file|
      options[:output_file] = file
    end
  end
end

#run(args) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/trustworthy/cli/crypt.rb', line 20

def run(args)
  catch(:error) do
    options = _check_options(args)
    prompt = Trustworthy::Prompt.new(options[:config_file], $terminal)
    File.open(options[:input_file], 'rb') do |input_file|
      _transform(prompt, options, input_file)
    end
  end
end