MCPcopy Index your code
hub / github.com/larksuite/cli / buildCmdExampleCatalog

Function buildCmdExampleCatalog

cmd/cmdexample_test.go:89–113  ·  view source on GitHub ↗

buildCmdExampleCatalog walks the live cobra command tree and records every command path (minus the "lark-cli" root prefix) with its accepted flags and whether it is a parent group. This is the same Build() the binary uses, so the catalog can never drift from the real commands.

()

Source from the content-addressed store, hash-verified

87// whether it is a parent group. This is the same Build() the binary uses, so
88// the catalog can never drift from the real commands.
89func buildCmdExampleCatalog() *catalog {
90 root := cmd.Build(context.Background(), cmdutil.InvocationContext{})
91 cat := newCatalog()
92 var walk func(c *cobra.Command)
93 walk = func(c *cobra.Command) {
94 path := strings.TrimSpace(strings.TrimPrefix(c.CommandPath(), "lark-cli"))
95 var flags []string
96 add := func(fl *pflag.Flag) {
97 flags = append(flags, "--"+fl.Name)
98 if fl.Shorthand != "" {
99 flags = append(flags, "-"+fl.Shorthand)
100 }
101 }
102 c.Flags().VisitAll(add)
103 c.InheritedFlags().VisitAll(add)
104 c.PersistentFlags().VisitAll(add) // root's own persistent flags (e.g. --profile)
105 cat.addCommand(path, flags)
106 cat.setGroup(path, c.HasSubCommands())
107 for _, sub := range c.Commands() {
108 walk(sub)
109 }
110 }
111 walk(root)
112 return cat
113}

Callers 1

Calls 6

BuildFunction · 0.92
newCatalogFunction · 0.85
CommandPathMethod · 0.80
addCommandMethod · 0.80
setGroupMethod · 0.80
walkFunction · 0.70

Tested by

no test coverage detected