MCPcopy
hub / github.com/spf13/cobra / gen

Function gen

bash_completions.go:652–680  ·  view source on GitHub ↗
(buf io.StringWriter, cmd *Command)

Source from the content-addressed store, hash-verified

650}
651
652func 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.
683func (c *Command) GenBashCompletion(w io.Writer) error {

Callers 1

GenBashCompletionMethod · 0.85

Calls 10

WriteStringAndCheckFunction · 0.85
writeCommandsFunction · 0.85
writeFlagsFunction · 0.85
writeRequiredFlagFunction · 0.85
writeRequiredNounsFunction · 0.85
writeArgAliasesFunction · 0.85
CommandsMethod · 0.80
IsAvailableCommandMethod · 0.80
CommandPathMethod · 0.80
RootMethod · 0.80

Tested by

no test coverage detected