| @@ -253,12 +253,13 @@ func pass(use string, o passOpts) *cobra.Command { |
| 253 | // The registry is the only place flags are written down, so |
253 | // The registry is the only place flags are written down, so |
| 254 | // --help asks the server rather than reprinting the one-line |
254 | // --help asks the server rather than reprinting the one-line |
| 255 | // summary cobra holds. |
255 | // summary cobra holds. |
| |
256 | cliPath := cliPathOf(cmd) |
| 256 | for _, a := range args { |
257 | for _, a := range args { |
| 257 | if a == "--help" || a == "-h" { |
258 | if a == "--help" || a == "-h" { |
| 258 | os.Exit(runServerHelp(o)) |
259 | os.Exit(runServerHelp(o, cliPath)) |
| 259 | } |
260 | } |
| 260 | } |
261 | } |
| 261 | os.Exit(runPass(o, args)) |
262 | os.Exit(runPass(o, cliPath, args)) |
| 262 | return nil |
263 | return nil |
| 263 | }, |
264 | }, |
| 264 | } |
265 | } |
| @@ -276,16 +277,17 @@ func withShort(cmd *cobra.Command, short string) *cobra.Command { |
| 276 | } |
277 | } |
| 277 | |
278 | |
| 278 | // runServerHelp prints the registry's usage for one command. |
279 | // runServerHelp prints the registry's usage for one command. |
| 279 | func runServerHelp(o passOpts) int { |
280 | func runServerHelp(o passOpts, cliPath string) int { |
| 280 | t, err := resolveTarget() |
281 | t, err := resolveTarget() |
| 281 | if err != nil { |
282 | if err != nil { |
| 282 | fmt.Fprintln(os.Stderr, "gitbay:", err) |
283 | fmt.Fprintln(os.Stderr, "gitbay:", err) |
| 283 | return protocol.ExitFailure |
284 | return protocol.ExitFailure |
| 284 | } |
285 | } |
| 285 | return runSSH(t, append([]string{"help"}, o.server...), strings.NewReader("")) |
286 | argv := withCLIPath(cliPath, strings.Join(o.server, " "), append([]string{"help"}, o.server...)) |
| |
287 | return runSSH(t, argv, strings.NewReader("")) |
| 286 | } |
288 | } |
| 287 | |
289 | |
| 288 | func runPass(o passOpts, args []string) int { |
290 | func runPass(o passOpts, cliPath string, args []string) int { |
| 289 | t, err := resolveTarget() |
291 | t, err := resolveTarget() |
| 290 | if err != nil { |
292 | if err != nil { |
| 291 | fmt.Fprintln(os.Stderr, "gitbay:", err) |
293 | fmt.Fprintln(os.Stderr, "gitbay:", err) |
| @@ -343,7 +345,8 @@ func runPass(o passOpts, args []string) int { |
| 343 | stdin = r |
345 | stdin = r |
| 344 | } |
346 | } |
| 345 | } |
347 | } |
| 346 | return runSSHPaged(t, append(o.server, args...), stdin, pages(o.server, args)) |
348 | argv := withCLIPath(cliPath, strings.Join(o.server, " "), append(o.server, args...)) |
| |
349 | return runSSHPaged(t, argv, stdin, pages(o.server, args)) |
| 347 | } |
350 | } |
| 348 | |
351 | |
| 349 | func isEmptyReader(r io.Reader) bool { |
352 | func isEmptyReader(r io.Reader) bool { |
| @@ -380,7 +383,7 @@ func group(use, short string, subs ...*cobra.Command) *cobra.Command { |
| 380 | // know by that name, cobra's own tree still prints. |
383 | // know by that name, cobra's own tree still prints. |
| 381 | local := c.HelpFunc() |
384 | local := c.HelpFunc() |
| 382 | c.SetHelpFunc(func(cmd *cobra.Command, args []string) { |
385 | c.SetHelpFunc(func(cmd *cobra.Command, args []string) { |
| 383 | if !serverHelp(use) { |
386 | if !serverHelp(use, cliPathOf(c)) { |
| 384 | local(cmd, args) |
387 | local(cmd, args) |
| 385 | } |
388 | } |
| 386 | }) |
389 | }) |
| @@ -388,19 +391,21 @@ func group(use, short string, subs ...*cobra.Command) *cobra.Command { |
| 388 | } |
391 | } |
| 389 | |
392 | |
| 390 | // serverHelp prints the registry's usage for a prefix and reports whether |
393 | // serverHelp prints the registry's usage for a prefix and reports whether |
| 391 | // it did. At a terminal it goes through the terminal-aware path, so it |
394 | // it did. cliPath is the group's own path in the CLI. At a terminal it |
| 392 | // gets the same --term=<cols>[,color] treatment (and layout) as any other |
395 | // goes through the terminal-aware path, so it gets the same |
| 393 | // command; piped, it stays a quiet capture, so a network or lookup |
396 | // --term=<cols>[,color] treatment (and layout) as any other command; |
| 394 | // failure falls back to cobra's local help without noise. |
397 | // piped, it stays a quiet capture, so a network or lookup failure falls |
| 395 | func serverHelp(prefix string) bool { |
398 | // back to cobra's local help without noise. |
| |
399 | func serverHelp(prefix, cliPath string) bool { |
| 396 | t, err := resolveTarget() |
400 | t, err := resolveTarget() |
| 397 | if err != nil { |
401 | if err != nil { |
| 398 | return false |
402 | return false |
| 399 | } |
403 | } |
| |
404 | argv := withCLIPath(cliPath, prefix, []string{"help", prefix}) |
| 400 | if term.IsTerminal(int(os.Stdout.Fd())) { |
405 | if term.IsTerminal(int(os.Stdout.Fd())) { |
| 401 | return runSSH(t, []string{"help", prefix}, strings.NewReader("")) == 0 |
406 | return runSSH(t, argv, strings.NewReader("")) == 0 |
| 402 | } |
407 | } |
| 403 | out, code := sshCapture(t, []string{"help", prefix}) |
408 | out, code := sshCapture(t, argv) |
| 404 | if code != 0 || out == "" { |
409 | if code != 0 || out == "" { |
| 405 | return false |
410 | return false |
| 406 | } |
411 | } |