MCPcopy Create free account
hub / github.com/algolia/cli / GenYamlTree

Function GenYamlTree

internal/docs/yaml.go:13–41  ·  view source on GitHub ↗
(cmd *cobra.Command, dir string)

Source from the content-addressed store, hash-verified

11)
12
13func GenYamlTree(cmd *cobra.Command, dir string) error {
14 commands := getCommands(cmd)
15
16 for _, c := range commands {
17 commandPath := strings.ReplaceAll(c.Name, " ", "_")
18 filename := filepath.Join(dir, fmt.Sprintf("%s.yml", commandPath))
19 f, err := os.Create(filename)
20 if err != nil {
21 return err
22 }
23 defer f.Close()
24
25 // Write a comment to the file, ignoring vale errors
26 _, err = f.WriteString("# <!-- vale off -->\n")
27 if err != nil {
28 return err
29 }
30
31 encoder := yaml.NewEncoder(f)
32 defer encoder.Close()
33
34 err = encoder.Encode(c)
35 if err != nil {
36 return err
37 }
38 }
39
40 return nil
41}

Callers

nothing calls this directly

Calls 3

getCommandsFunction · 0.85
CreateMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected