GenBashCompletion generates bash completion file and writes to the passed writer.
(w io.Writer)
| 681 | |
| 682 | // GenBashCompletion generates bash completion file and writes to the passed writer. |
| 683 | func (c *Command) GenBashCompletion(w io.Writer) error { |
| 684 | buf := new(bytes.Buffer) |
| 685 | writePreamble(buf, c.Name()) |
| 686 | if len(c.BashCompletionFunction) > 0 { |
| 687 | buf.WriteString(c.BashCompletionFunction + "\n") |
| 688 | } |
| 689 | gen(buf, c) |
| 690 | writePostscript(buf, c.Name()) |
| 691 | |
| 692 | _, err := buf.WriteTo(w) |
| 693 | return err |
| 694 | } |
| 695 | |
| 696 | func nonCompletableFlag(flag *pflag.Flag) bool { |
| 697 | return flag.Hidden || len(flag.Deprecated) > 0 |