Class: Legion::CLI::Doctor::ConfigCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/cli/doctor/config_check.rb

Constant Summary collapse

CONFIG_PATHS =
[
  File.expand_path('~/.legionio/settings'),
  '/etc/legionio',
  File.expand_path('./settings')
].freeze

Instance Method Summary collapse

Instance Method Details

#fixObject



50
51
52
# File 'lib/legion/cli/doctor/config_check.rb', line 50

def fix
  system('legion config scaffold')
end

#nameObject



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

def name
  'Config files'
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/legion/cli/doctor/config_check.rb', line 19

def run
  found_dirs = CONFIG_PATHS.select { |p| Dir.exist?(p) }

  if found_dirs.empty?
    return Result.new(
      name:         name,
      status:       :warn,
      message:      "No config directory found (checked: #{CONFIG_PATHS.join(', ')})",
      prescription: 'Run `legion config scaffold` to generate starter config',
      auto_fixable: true
    )
  end

  invalid_files = find_invalid_json_files(found_dirs)
  if invalid_files.any?
    messages = invalid_files.map { |f, err| "#{f}: #{err}" }
    return Result.new(
      name:         name,
      status:       :fail,
      message:      "Invalid JSON in config files: #{messages.join('; ')}",
      prescription: messages.map { |m| "Fix JSON syntax error in #{m}" }.join('; ')
    )
  end

  Result.new(
    name:    name,
    status:  :pass,
    message: "Config found in: #{found_dirs.join(', ')}"
  )
end