Commit 1c22065e25
Verified · cmc ci/build: success ci/test: success ci/vuln: success
Layout: unified · split
cmd/gitbay/coverage_test.go +3 −2
| @@ -13,7 +13,6 @@ import ( | ||
| 13 | 13 | // registry must be reachable by typing it, or the CLI is not the |
| 14 | 14 | // complete interface the design claims. |
| 15 | 15 | var notInCLI = map[string]string{ |
| 16 | "help": "cobra owns `gitbay help`; the registry's is reached by `<cmd> --help`", | |
| 17 | 16 | "runner next": "the CI runner's wire protocol, not for humans", |
| 18 | 17 | "runner done": "the CI runner's wire protocol, not for humans", |
| 19 | 18 | "runner log": "the CI runner's wire protocol, not for humans", |
| @@ -36,7 +35,9 @@ func TestEveryCommandIsReachable(t *testing.T) { | ||
| 36 | 35 | walk(sub) |
| 37 | 36 | } |
| 38 | 37 | } |
| 39 | walk(newRoot()) | |
| 38 | root := newRoot() | |
| 39 | root.InitDefaultHelpCmd() // attaches the help command the way Execute does | |
| 40 | walk(root) | |
| 40 | 41 | |
| 41 | 42 | for _, cmd := range control.Commands() { |
| 42 | 43 | path := strings.Join(cmd.Path, " ") |
cmd/gitbay/main.go +27
| @@ -32,6 +32,7 @@ func newRoot() *cobra.Command { | ||
| 32 | 32 | SilenceUsage: true, |
| 33 | 33 | SilenceErrors: true, |
| 34 | 34 | } |
| 35 | root.SetHelpCommand(helpCmd(root)) | |
| 35 | 36 | |
| 36 | 37 | root.AddCommand( |
| 37 | 38 | authCmd(), |
| @@ -576,3 +577,29 @@ func manCmd(root *cobra.Command) *cobra.Command { | ||
| 576 | 577 | cmd.Flags().StringVar(&dir, "dir", "man", "output directory") |
| 577 | 578 | return cmd |
| 578 | 579 | } |
| 580 | ||
| 581 | // helpCmd is `gitbay help`. Bare, it is cobra's tree of local commands. | |
| 582 | // With anything after it — a prefix such as `mr`, or --json — it is the | |
| 583 | // server's help: the registry is the only place flags are written down, | |
| 584 | // and its JSON is the contract. Cobra's built-in help used to swallow | |
| 585 | // both forms, so `gitbay help --json` failed on an unknown flag. | |
| 586 | func helpCmd(root *cobra.Command) *cobra.Command { | |
| 587 | return &cobra.Command{ | |
| 588 | Use: "help [<prefix>...] [--json]", | |
| 589 | Short: "this list, or the server's command reference for a prefix", | |
| 590 | Annotations: map[string]string{serverPath: "help", stdinMode: "none"}, | |
| 591 | DisableFlagParsing: true, | |
| 592 | RunE: func(cmd *cobra.Command, args []string) error { | |
| 593 | if len(args) == 0 { | |
| 594 | return root.Help() | |
| 595 | } | |
| 596 | t, err := resolveTarget() | |
| 597 | if err != nil { | |
| 598 | fmt.Fprintln(os.Stderr, "gitbay:", err) | |
| 599 | os.Exit(protocol.ExitFailure) | |
| 600 | } | |
| 601 | os.Exit(runSSH(t, append([]string{"help"}, args...), strings.NewReader(""))) | |
| 602 | return nil | |
| 603 | }, | |
| 604 | } | |
| 605 | } | |