MCPcopy Create free account
hub / github.com/basecamp/hey-cli / printAgentHelp

Function printAgentHelp

internal/cmd/root.go:266–311  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

264}
265
266func printAgentHelp(cmd *cobra.Command) {
267 info := map[string]any{
268 "name": cmd.Name(),
269 "use": cmd.Use,
270 "short": cmd.Short,
271 }
272 if cmd.Long != "" {
273 info["long"] = cmd.Long
274 }
275 if notes, ok := cmd.Annotations["agent_notes"]; ok {
276 info["agent_notes"] = notes
277 }
278
279 var flags []map[string]string
280 addFlag := func(f *pflag.Flag) {
281 flags = append(flags, map[string]string{
282 "name": f.Name,
283 "shorthand": f.Shorthand,
284 "usage": f.Usage,
285 "default": f.DefValue,
286 })
287 }
288 cmd.LocalFlags().VisitAll(addFlag)
289 cmd.InheritedFlags().VisitAll(addFlag)
290 if len(flags) > 0 {
291 info["flags"] = flags
292 }
293
294 var subs []map[string]string
295 for _, sub := range cmd.Commands() {
296 if sub.Hidden || !sub.IsAvailableCommand() {
297 continue
298 }
299 subs = append(subs, map[string]string{
300 "name": sub.Name(),
301 "short": sub.Short,
302 })
303 }
304 if len(subs) > 0 {
305 info["subcommands"] = subs
306 }
307
308 enc := json.NewEncoder(cmd.OutOrStdout())
309 enc.SetIndent("", " ")
310 _ = enc.Encode(info)
311}

Callers 1

customHelpFuncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected