MCPcopy
hub / github.com/cli/cli / rootUsageFunc

Function rootUsageFunc

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

Source from the content-addressed store, hash-verified

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