Class: EnvSpec::CLI

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

Constant Summary collapse

SUBCOMMANDS =
%w[lint check init help version].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



7
8
9
# File 'lib/envspec/cli.rb', line 7

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

Instance Method Details

#run(argv) ⇒ Object



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
39
40
# File 'lib/envspec/cli.rb', line 11

def run(argv)
  argv = argv.dup
  cmd = argv.shift

  case cmd
  when nil, "help", "-h", "--help"
    print_help(argv.first)
    0
  when "version", "-v", "--version"
    puts EnvSpec::VERSION
    0
  when "lint"
    cmd_lint(argv)
  when "check"
    cmd_check(argv)
  when "init"
    cmd_init(argv)
  else
    warn "envspec: unknown command '#{cmd}'"
    warn ""
    print_help
    2
  end
rescue OptionParser::ParseError => e
  warn "envspec: #{e.message}"
  2
rescue EnvSpec::ParseError, EnvSpec::ValidationError => e
  warn "envspec: #{e.message}"
  1
end