/
configcmd.go
83 lines (73 loc) · 1.82 KB
/
configcmd.go
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
75
76
77
78
79
80
81
82
83
package config
import (
"encoding/json"
"fmt"
"cuelang.org/go/cue/format"
"github.com/spf13/cobra"
)
// Cmd command: The Area for which the config is to be printed need to be passed. This will be done by Dingo if a Provider is used for example.
func Cmd(area *Area) *cobra.Command {
var contextName string
cmd := &cobra.Command{
Use: "config",
Short: "Config dump",
Run: func(cmd *cobra.Command, args []string) {
if contextName != "" {
flatArea, _ := area.Flat()
for _, c := range flatArea {
if c.Name == contextName {
area = c
break
}
}
}
if len(args) > 0 {
for _, c := range args {
cfg, _ := area.Config(c)
x, _ := json.MarshalIndent(cfg, "", " ")
fmt.Println(c + ":")
fmt.Println(string(x))
fmt.Println()
}
} else {
dumpConfigArea(area)
}
},
}
cmd.Flags().StringVarP(
&contextName,
"context",
"c",
"",
"Name of the context (relative context path) - set this if you like to see only this context. Otherwise it will show all.",
)
return cmd
}
func dumpConfigArea(a *Area) {
fmt.Println()
fmt.Println("**************************")
fmt.Println("Area: ", a.Name)
fmt.Println("**************************")
if false { //cuedump {
// build a cue runtime to verify the config
//cueRuntime := new(cue.Runtime)
//ci, err := cueRuntime.Build(a.cueBuildInstance)
//if err != nil {
// panic(err)
//}
for _, f := range a.cueBuildInstance.Files {
d, _ := format.Node(f, format.Simplify())
fmt.Println("//", f.Filename)
fmt.Println(string(d))
fmt.Println("")
}
//d, _ := format.Node(ci.Value().Syntax(), format.Simplify())
//fmt.Println(string(d))
} else {
x, _ := json.MarshalIndent(a.Configuration, "", " ")
fmt.Println(string(x))
}
for _, routeConfig := range a.Childs {
dumpConfigArea(routeConfig)
}
}