Class: EnvSpec::CLI::Check

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

Instance Method Summary collapse

Methods inherited from Command

banner, #build_parser, description, #help, #initialize, name, #parser, #run, summary

Constructor Details

This class inherits a constructor from EnvSpec::CLI::Command

Instance Method Details

#call(rest, opts) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/envspec/cli/check.rb', line 23

def call(rest, opts)
  file = require_file(rest.shift)
  spec = EnvSpec.parse_file(file)
  spec.validate!(ENV.to_h, env: opts[:env], strict: opts[:strict])
  label = opts[:env] == "*" ? "shared" : opts[:env]
  puts "✓ ENV satisfies #{file} (env: #{label})"
  0
end

#configure(o, opts) ⇒ Object



18
19
20
21
# File 'lib/envspec/cli/check.rb', line 18

def configure(o, opts)
  o.on("--env=NAME", "Env scope to validate against (default: shared/*)") { |v| opts[:env] = v }
  o.on("--strict", "Treat unknown env vars as problems")                  { opts[:strict] = true }
end

#default_optsObject



14
15
16
# File 'lib/envspec/cli/check.rb', line 14

def default_opts
  { env: "*", strict: false }
end