Class: Ironclad::CLI

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

Overview

Command-line entry point. Dependency-free arg parsing keeps boot cheap and avoids loading Rails just to print a key.

ironclad [env]               print the credentials key (default env)
ironclad refresh [env]       re-cache one environment's key
ironclad refresh --all       re-cache every environment's key
ironclad edit [env]          edit Rails credentials for env
ironclad diff <file>         git textconv: decrypt a credentials file

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



19
20
21
# File 'lib/ironclad/cli.rb', line 19

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.start(argv) ⇒ Object



15
16
17
# File 'lib/ironclad/cli.rb', line 15

def self.start(argv)
  new(argv).run
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ironclad/cli.rb', line 23

def run
  case @argv.first
  when 'refresh'
    @argv.shift
    return refresh
  when 'edit'
    @argv.shift
    edit(@argv.shift || 'default')
  when 'diff'
    @argv.shift
    diff(@argv.shift)
  when '-h', '--help', 'help'
    print_help
  else
    print_key
  end
  0
rescue Error => e
  warn e.message
  1
end