(w io.Writer, command *cobra.Command)
| 18 | ) |
| 19 | |
| 20 | func 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 | |
| 47 | func rootFlagErrorFunc(cmd *cobra.Command, err error) error { |
| 48 | if err == pflag.ErrHelp { |
no test coverage detected