Class: EdgeCastToken::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ectoken/cli.rb

Class Method Summary collapse

Class Method Details

.mainObject



3
4
5
6
7
8
9
10
11
12
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
# File 'lib/ectoken/cli.rb', line 3

def self.main
  @options = {}

  option_parser = OptionParser.new do |opts|
    opts.on('-v', '--version', 'Show version') do |v|
      puts EdgeCastToken::VERSION
      exit
    end

    opts.on('-k', '--key=KEY', 'Key to encrypt or decrypt') do |v|
      @options[:key] = v
    end

    opts.on('-t', '--token=TOKEN', 'Token to encrypt or decrypt') do |v|
      @options[:token] = v
    end

    opts.on('-d', '--decrypt', 'Use this option to decrypt data') do |v|
      @options[:decrypt] = true
    end
  end

  option_parser.parse!

  if @options[:key].nil? || @options[:token].nil?
    puts option_parser.help
    exit 1
  end

  case @options[:decrypt].nil?
  when true
    puts Token.encrypt(@options[:key], @options[:token])
  when false
    puts Token.decrypt(@options[:key], @options[:token])
  end
end