-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_doctor.go
More file actions
74 lines (64 loc) · 1.9 KB
/
Copy pathmain_doctor.go
File metadata and controls
74 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
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
41
42
43
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
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/marcelo-lipienski/halo/config"
"github.com/marcelo-lipienski/halo/doctor"
"github.com/marcelo-lipienski/halo/output"
)
func executeDoctor() int {
format = strings.ToLower(format)
if format != "text" && format != "json" {
fmt.Fprintf(stderr, "Invalid format: %s. Supported formats: text, json\n", format)
return 1
}
var filesToLoad []string
if len(composeFiles) > 0 {
filesToLoad = composeFiles
} else {
composePathYml := filepath.Join(configDir, "docker-compose.yml")
composePathYaml := filepath.Join(configDir, "docker-compose.yaml")
composePath := composePathYaml
if _, err := os.Stat(composePathYml); err == nil {
composePath = composePathYml
}
filesToLoad = append(filesToLoad, composePath)
overridePathYml := filepath.Join(configDir, "docker-compose.override.yml")
overridePathYaml := filepath.Join(configDir, "docker-compose.override.yaml")
if _, err := os.Stat(overridePathYml); err == nil {
filesToLoad = append(filesToLoad, overridePathYml)
} else if _, err := os.Stat(overridePathYaml); err == nil {
filesToLoad = append(filesToLoad, overridePathYaml)
}
}
var parsedConfigs []*config.ComposeConfig
for _, file := range filesToLoad {
if _, err := os.Stat(file); err == nil {
if parsed, err := config.ParseCompose(file); err == nil {
parsedConfigs = append(parsedConfigs, parsed)
}
}
}
var comp *config.ComposeConfig
if len(parsedConfigs) > 0 {
comp = config.MergeComposeConfigs(parsedConfigs...)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
report := doctor.RunDoctor(ctx, configDir, comp)
if !quiet {
if format == "json" {
_ = output.RenderJSON(stdout, report)
} else {
output.RenderText(stdout, report, verbose)
}
}
if report.Status == output.StatusEnvironmentBroken {
return 2
}
return 0
}