MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / GenJSONTree

Function GenJSONTree

cmd/internal/commands/doc.go:125–150  ·  view source on GitHub ↗

GenTree generates a JSON tree for the given root command

(root *cobra.Command)

Source from the content-addressed store, hash-verified

123
124// GenTree generates a JSON tree for the given root command
125func GenJSONTree(root *cobra.Command) *cobra.Command {
126 cmd := &cobra.Command{
127 Use: "gen-json-tree",
128 Hidden: true,
129 Short: fmt.Sprintf("Generate JSON tree for %s", root.Name()),
130 RunE: func(cmd *cobra.Command, args []string) error {
131 dir, _ := cmd.Flags().GetString("out")
132
133 out := filepath.Join(dir, root.Name()+".json")
134
135 f, err := os.Create(out)
136 if err != nil {
137 return err
138 }
139 defer f.Close()
140
141 enc := json.NewEncoder(f)
142 enc.SetIndent("", " ")
143 return enc.Encode(map[string]command{
144 cmd.Root().Name(): commandTree(cmd.Root()),
145 })
146 },
147 }
148 cmd.Flags().StringP("out", "o", "doc", "output directory")
149 return cmd
150}

Callers 2

root.goFile · 0.92
root.goFile · 0.92

Calls 8

commandTreeFunction · 0.85
FlagsMethod · 0.80
NewEncoderMethod · 0.80
NameMethod · 0.65
JoinMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65
EncodeMethod · 0.65

Tested by

no test coverage detected