(buf io.StringWriter, cmd *Command)
| 650 | } |
| 651 | |
| 652 | func gen(buf io.StringWriter, cmd *Command) { |
| 653 | for _, c := range cmd.Commands() { |
| 654 | if !c.IsAvailableCommand() && c != cmd.helpCommand { |
| 655 | continue |
| 656 | } |
| 657 | gen(buf, c) |
| 658 | } |
| 659 | commandName := cmd.CommandPath() |
| 660 | commandName = strings.ReplaceAll(commandName, " ", "_") |
| 661 | commandName = strings.ReplaceAll(commandName, ":", "__") |
| 662 | |
| 663 | if cmd.Root() == cmd { |
| 664 | WriteStringAndCheck(buf, fmt.Sprintf("_%s_root_command()\n{\n", commandName)) |
| 665 | } else { |
| 666 | WriteStringAndCheck(buf, fmt.Sprintf("_%s()\n{\n", commandName)) |
| 667 | } |
| 668 | |
| 669 | WriteStringAndCheck(buf, fmt.Sprintf(" last_command=%q\n", commandName)) |
| 670 | WriteStringAndCheck(buf, "\n") |
| 671 | WriteStringAndCheck(buf, " command_aliases=()\n") |
| 672 | WriteStringAndCheck(buf, "\n") |
| 673 | |
| 674 | writeCommands(buf, cmd) |
| 675 | writeFlags(buf, cmd) |
| 676 | writeRequiredFlag(buf, cmd) |
| 677 | writeRequiredNouns(buf, cmd) |
| 678 | writeArgAliases(buf, cmd) |
| 679 | WriteStringAndCheck(buf, "}\n\n") |
| 680 | } |
| 681 | |
| 682 | // GenBashCompletion generates bash completion file and writes to the passed writer. |
| 683 | func (c *Command) GenBashCompletion(w io.Writer) error { |
no test coverage detected