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



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

def _check_options(args)
  options = parse_options(args)
  unless options[:input_file] && options[:output_file]
    print_help
    throw :error
  end
  options
end

#_commandObject



28
29
30
# File 'lib/trustworthy/cli/crypt.rb', line 28

def _command
  self.class._command
end

#parse_options(args) ⇒ Object



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

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

#run(args) ⇒ Object



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

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