Skip to content
Myr

Use func (c *Command) consistently (#530)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

It makes the docs looks better. The idea was suggested by @SamWhited

authored by Eric Paris · committed by GitHub · parent 4de692c · Browse files · 2 files+24 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−24 removed

  • other:+24 added−24 removed

2 files+24 added−24 removed

modified:bash_completions.go+18 added-18 removed
461 unmodified lines
462 buf.WriteString("}\n\n")463}464465// GenBashCompletion generates bash completion file and writes to the passed writer.466func (cmd *Command) GenBashCompletion(w io.Writer) error {466func (c *Command) GenBashCompletion(w io.Writer) error {467 buf := new(bytes.Buffer)468 writePreamble(buf, cmd.Name())469 if len(cmd.BashCompletionFunction) > 0 {470 buf.WriteString(cmd.BashCompletionFunction + "\n")468 writePreamble(buf, c.Name())469 if len(c.BashCompletionFunction) > 0 {470 buf.WriteString(c.BashCompletionFunction + "\n")471 }472 gen(buf, cmd)473 writePostscript(buf, cmd.Name())472 gen(buf, c)473 writePostscript(buf, c.Name())474475 _, err := buf.WriteTo(w)476 return err477}
2 unmodified lines
480 return flag.Hidden || len(flag.Deprecated) > 0481}482483// GenBashCompletionFile generates bash completion file.484func (cmd *Command) GenBashCompletionFile(filename string) error {484func (c *Command) GenBashCompletionFile(filename string) error {485 outFile, err := os.Create(filename)486 if err != nil {487 return err488 }489 defer outFile.Close()490491 return cmd.GenBashCompletion(outFile)491 return c.GenBashCompletion(outFile)492}493494// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag, if it exists.495func (cmd *Command) MarkFlagRequired(name string) error {496 return MarkFlagRequired(cmd.Flags(), name)495func (c *Command) MarkFlagRequired(name string) error {496 return MarkFlagRequired(c.Flags(), name)497}498499// MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag, if it exists.500func (cmd *Command) MarkPersistentFlagRequired(name string) error {501 return MarkFlagRequired(cmd.PersistentFlags(), name)500func (c *Command) MarkPersistentFlagRequired(name string) error {501 return MarkFlagRequired(c.PersistentFlags(), name)502}503504// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists.505func MarkFlagRequired(flags *pflag.FlagSet, name string) error {
1 unmodified line
507}508509// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag, if it exists.510// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.511func (cmd *Command) MarkFlagFilename(name string, extensions ...string) error {512 return MarkFlagFilename(cmd.Flags(), name, extensions...)511func (c *Command) MarkFlagFilename(name string, extensions ...string) error {512 return MarkFlagFilename(c.Flags(), name, extensions...)513}514515// MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists.516// Generated bash autocompletion will call the bash function f for the flag.517func (cmd *Command) MarkFlagCustom(name string, f string) error {518 return MarkFlagCustom(cmd.Flags(), name, f)517func (c *Command) MarkFlagCustom(name string, f string) error {518 return MarkFlagCustom(c.Flags(), name, f)519}520521// MarkPersistentFlagFilename adds the BashCompFilenameExt annotation to the named persistent flag, if it exists.522// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.523func (cmd *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {524 return MarkFlagFilename(cmd.PersistentFlags(), name, extensions...)523func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {524 return MarkFlagFilename(c.PersistentFlags(), name, extensions...)525}526527// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag in the flag set, if it exists.528// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.
9 unmodified lines
modified:zsh_completions.go+6 added-6 removed
7 unmodified lines
8 "strings"9)1011// GenZshCompletionFile generates zsh completion file.12func (cmd *Command) GenZshCompletionFile(filename string) error {12func (c *Command) GenZshCompletionFile(filename string) error {13 outFile, err := os.Create(filename)14 if err != nil {15 return err16 }17 defer outFile.Close()1819 return cmd.GenZshCompletion(outFile)19 return c.GenZshCompletion(outFile)20}2122// GenZshCompletion generates a zsh completion file and writes to the passed writer.23func (cmd *Command) GenZshCompletion(w io.Writer) error {23func (c *Command) GenZshCompletion(w io.Writer) error {24 buf := new(bytes.Buffer)2526 writeHeader(buf, cmd)27 maxDepth := maxDepth(cmd)26 writeHeader(buf, c)27 maxDepth := maxDepth(c)28 writeLevelMapping(buf, maxDepth)29 writeLevelCases(buf, maxDepth, cmd)29 writeLevelCases(buf, maxDepth, c)3031 _, err := buf.WriteTo(w)32 return err33}
93 unmodified lines