MCPcopy Create free account
hub / github.com/cli/cli / rootUsageFunc

Function rootUsageFunc

pkg/cmd/root/help.go:20–45  ·  view source on GitHub ↗
(w io.Writer, command *cobra.Command)

Source from the content-addressed store, hash-verified

18)
19
20func rootUsageFunc(w io.Writer, command *cobra.Command) error {
21 fmt.Fprintf(w, "Usage: %s", command.UseLine())
22
23 var subcommands []*cobra.Command
24 for _, c := range command.Commands() {
25 if !c.IsAvailableCommand() {
26 continue
27 }
28 subcommands = append(subcommands, c)
29 }
30
31 if len(subcommands) > 0 {
32 fmt.Fprint(w, "\n\nAvailable commands:\n")
33 for _, c := range subcommands {
34 fmt.Fprintf(w, " %s\n", c.Name())
35 }
36 return nil
37 }
38
39 flagUsages := command.LocalFlags().FlagUsages()
40 if flagUsages != "" {
41 fmt.Fprintln(w, "\n\nFlags:")
42 fmt.Fprint(w, text.Indent(dedent(flagUsages), " "))
43 }
44 return nil
45}
46
47func rootFlagErrorFunc(cmd *cobra.Command, err error) error {
48 if err == pflag.ErrHelp {

Callers 2

nestedSuggestFuncFunction · 0.85
NewCmdRootFunction · 0.85

Calls 3

IndentFunction · 0.92
dedentFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected