Class: EnvSpec::CLI::Init

Inherits:
Command
  • Object
show all
Defined in:
lib/envspec/cli/init.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



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

def call(_rest, opts)
  result = EnvSpec::Init.run(root: opts[:root], force: opts[:force], output: opts[:output])

  unless result[:ok]
    if result[:reason] == :exists
      return die("#{opts[:output]} already exists (use --force to overwrite)", 1)
    end
    return die("init failed: #{result[:reason]}", 1)
  end

  puts "✓ Scanned in #{format('%.2fs', result[:elapsed])}"
  puts "✓ Found #{result[:keys]} env vars across #{result[:files]} files"
  puts "✓ Wrote #{result[:path]}"
  puts ""
  puts "Next steps:"
  puts "  1. Edit #{opts[:output]} — review heuristic suggestions, classify secrets"
  puts "  2. Run `envspec lint #{opts[:output]}` to validate"
  puts "  3. Run `envspec check #{opts[:output]}` to test against your current ENV"
  0
end

#configure(o, opts) ⇒ Object



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

def configure(o, opts)
  o.on("--force",       "Overwrite an existing env.spec")    { opts[:force] = true }
  o.on("--output=PATH", "Output file (default: env.spec)")   { |v| opts[:output] = v }
  o.on("--root=PATH",   "Directory to scan (default: cwd)")  { |v| opts[:root] = v }
end

#default_optsObject



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

def default_opts
  { force: false, output: "env.spec", root: Dir.pwd }
end