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