Class: Keystok::CLI

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

Overview

Parses command line arguments and execute requested actions

Instance Method Summary collapse

Instance Method Details

#run(args = ARGV) ⇒ Object



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
# File 'lib/keystok/cli.rb', line 12

def run(args = ARGV)
  options = parse(args)
  access_token = options.access_token if options.access_token
  if !access_token && options.access_token_filepath
    access_token = YAML.load_file(options.access_token_filepath)
  end
  if access_token.nil?
    puts 'You have to use -c or -f option'
    exit 1
  end
  client = Keystok::Client.new(access_token)
  case options.command
  when :dump
    puts dump_data(client.keys, options.dump_format)
  when :get
    if options.key_id
      puts client.get(options.key_id)
    else
      puts format_keys_list(client.keys)
    end
  else
    puts "Unknown command: #{options.command}"
    exit 1
  end
end