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
Provenance
- Commit
b787445- Tree
d88fbd4- Author
Eric Paris <eparis@redhat.com>- Committer
GitHub <noreply@github.com>- Parent
4de692c
2 files changed+24 added−24 removed
modified:bash_completions.go+18 added-18 removed
461 unmodified lines462 buf.WriteString("}\n\n")463 }464 465 // GenBashCompletion generates bash completion file and writes to the passed writer.466-func (cmd *Command) GenBashCompletion(w io.Writer) error {466+func (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())474 475 _, err := buf.WriteTo(w)476 return err477 }2 unmodified lines480 return flag.Hidden || len(flag.Deprecated) > 0481 }482 483 // GenBashCompletionFile generates bash completion file.484-func (cmd *Command) GenBashCompletionFile(filename string) error {484+func (c *Command) GenBashCompletionFile(filename string) error {485 outFile, err := os.Create(filename)486 if err != nil {487 return err488 }489 defer outFile.Close()490 491- return cmd.GenBashCompletion(outFile)491+ return c.GenBashCompletion(outFile)492 }493 494 // MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag, if it exists.495-func (cmd *Command) MarkFlagRequired(name string) error {496- return MarkFlagRequired(cmd.Flags(), name)495+func (c *Command) MarkFlagRequired(name string) error {496+ return MarkFlagRequired(c.Flags(), name)497 }498 499 // MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag, if it exists.500-func (cmd *Command) MarkPersistentFlagRequired(name string) error {501- return MarkFlagRequired(cmd.PersistentFlags(), name)500+func (c *Command) MarkPersistentFlagRequired(name string) error {501+ return MarkFlagRequired(c.PersistentFlags(), name)502 }503 504 // MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists.505 func MarkFlagRequired(flags *pflag.FlagSet, name string) error {1 unmodified line507 }508 509 // 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.511-func (cmd *Command) MarkFlagFilename(name string, extensions ...string) error {512- return MarkFlagFilename(cmd.Flags(), name, extensions...)511+func (c *Command) MarkFlagFilename(name string, extensions ...string) error {512+ return MarkFlagFilename(c.Flags(), name, extensions...)513 }514 515 // 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.517-func (cmd *Command) MarkFlagCustom(name string, f string) error {518- return MarkFlagCustom(cmd.Flags(), name, f)517+func (c *Command) MarkFlagCustom(name string, f string) error {518+ return MarkFlagCustom(c.Flags(), name, f)519 }520 521 // 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.523-func (cmd *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {524- return MarkFlagFilename(cmd.PersistentFlags(), name, extensions...)523+func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {524+ return MarkFlagFilename(c.PersistentFlags(), name, extensions...)525 }526 527 // 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 linesmodified:zsh_completions.go+6 added-6 removed
7 unmodified lines8 "strings"9 )10 11 // GenZshCompletionFile generates zsh completion file.12-func (cmd *Command) GenZshCompletionFile(filename string) error {12+func (c *Command) GenZshCompletionFile(filename string) error {13 outFile, err := os.Create(filename)14 if err != nil {15 return err16 }17 defer outFile.Close()18 19- return cmd.GenZshCompletion(outFile)19+ return c.GenZshCompletion(outFile)20 }21 22 // GenZshCompletion generates a zsh completion file and writes to the passed writer.23-func (cmd *Command) GenZshCompletion(w io.Writer) error {23+func (c *Command) GenZshCompletion(w io.Writer) error {24 buf := new(bytes.Buffer)25 26- 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)30 31 _, err := buf.WriteTo(w)32 return err33 }93 unmodified lines