MCPcopy
hub / github.com/hashicorp/hcl / realMain

Function realMain

cmd/hclspecsuite/main.go:21–80  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

19}
20
21func realMain(args []string) int {
22 if len(args) != 2 {
23 fmt.Fprintf(os.Stderr, "Usage: hclspecsuite <tests-dir> <hcldec-file>\n")
24 return 2
25 }
26
27 testsDir := args[0]
28 hcldecPath := args[1]
29
30 hcldecPath, err := exec.LookPath(hcldecPath)
31 if err != nil {
32 fmt.Fprintf(os.Stderr, "%s\n", err)
33 return 2
34 }
35
36 parser := hclparse.NewParser()
37
38 color := term.IsTerminal(int(os.Stderr.Fd()))
39 w, _, err := term.GetSize(int(os.Stdout.Fd()))
40 if err != nil {
41 w = 80
42 }
43 diagWr := hcl.NewDiagnosticTextWriter(os.Stderr, parser.Files(), uint(w), color)
44 var diagCount int
45
46 runner := &Runner{
47 parser: parser,
48 hcldecPath: hcldecPath,
49 baseDir: testsDir,
50 logBegin: func(name string, file *TestFile) {
51 fmt.Printf("- %s\n", name)
52 },
53 logProblems: func(name string, file *TestFile, diags hcl.Diagnostics) {
54 if len(diags) != 0 {
55 fmt.Fprint(os.Stderr, "\n")
56 err := diagWr.WriteDiagnostics(diags)
57 if err != nil {
58 fmt.Fprintf(os.Stderr, "Error writing diagnostics: %s\n", err)
59 }
60 diagCount += len(diags)
61 }
62 fmt.Printf("- %s\n", name)
63 },
64 }
65 diags := runner.Run()
66
67 if len(diags) != 0 {
68 fmt.Fprintf(os.Stderr, "\n\n\n== Test harness problems:\n\n")
69 err := diagWr.WriteDiagnostics(diags)
70 if err != nil {
71 fmt.Fprintf(os.Stderr, "Error writing diagnostics: %s\n", err)
72 }
73 diagCount += len(diags)
74 }
75
76 if diagCount > 0 {
77 return 2
78 }

Callers 1

mainFunction · 0.85

Calls 4

FilesMethod · 0.95
RunMethod · 0.95
NewParserFunction · 0.92
WriteDiagnosticsMethod · 0.65

Tested by

no test coverage detected