Class: Legion::CLI::Bootstrap

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/bootstrap_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


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

def self.exit_on_failure?
  true
end

Instance Method Details

#execute(source) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/legion/cli/bootstrap_command.rb', line 44

def execute(source)
  require_relative 'config_import'
  require_relative 'config_scaffold'
  require_relative 'setup_command'

  out     = formatter
  results = {}
  warns   = []

  # 1. Pre-flight checks
  print_step(out, 'Pre-flight checks')
  results[:preflight] = run_preflight_checks(out, warns)

  # 2. Clean existing config (--clean)
  results[:cleaned] = clean_settings(out) if options[:clean]

  # 3. Fetch + parse config
  print_step(out, "Fetching config from #{source}")
  body   = ConfigImport.fetch_source(source)
  config = ConfigImport.parse_payload(body)

  # 4. Extract packs before writing (bootstrap-only directive)
  pack_names = Array(config.delete(:packs)).map(&:to_s).reject(&:empty?)
  results[:packs_requested] = pack_names

  # 5. Write config
  paths = ConfigImport.write_config(config, force: options[:force])
  results[:config_written] = paths
  unless options[:json]
    if paths.empty?
      out.warn('No config files were written (config was empty after removing packs).')
    else
      paths.each { |p| out.success("Written: #{p}") }
    end
  end

  # 6. Scaffold missing subsystem files (skipped when source provided)
  results[:scaffold] = :skipped

  # 7. Install packs (unless --skip-packs)
  results[:packs_installed] = install_packs_step(pack_names, out)

  # 8. Post-bootstrap summary
  summary = build_summary(config, results, warns)
  results[:summary] = summary
  print_summary(out, summary)

  # 9. Optional --start
  if options[:start]
    print_step(out, 'Starting services')
    results[:services_started] = start_services(out)
  end

  out.json(results) if options[:json]
rescue CLI::Error => e
  formatter.error(e.message)
  raise SystemExit, 1
end