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

It makes the docs looks better. The idea was suggested by @SamWhited
This commit is contained in:
Eric Paris 2017-09-05 13:20:51 -04:00 committed by GitHub
parent 4de692c1eb
commit b787445794
2 changed files with 24 additions and 24 deletions

View File

@ -463,14 +463,14 @@ func gen(buf *bytes.Buffer, cmd *Command) {
} }
// GenBashCompletion generates bash completion file and writes to the passed writer. // GenBashCompletion generates bash completion file and writes to the passed writer.
func (cmd *Command) GenBashCompletion(w io.Writer) error { func (c *Command) GenBashCompletion(w io.Writer) error {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
writePreamble(buf, cmd.Name()) writePreamble(buf, c.Name())
if len(cmd.BashCompletionFunction) > 0 { if len(c.BashCompletionFunction) > 0 {
buf.WriteString(cmd.BashCompletionFunction + "\n") buf.WriteString(c.BashCompletionFunction + "\n")
} }
gen(buf, cmd) gen(buf, c)
writePostscript(buf, cmd.Name()) writePostscript(buf, c.Name())
_, err := buf.WriteTo(w) _, err := buf.WriteTo(w)
return err return err
@ -481,24 +481,24 @@ func nonCompletableFlag(flag *pflag.Flag) bool {
} }
// GenBashCompletionFile generates bash completion file. // GenBashCompletionFile generates bash completion file.
func (cmd *Command) GenBashCompletionFile(filename string) error { func (c *Command) GenBashCompletionFile(filename string) error {
outFile, err := os.Create(filename) outFile, err := os.Create(filename)
if err != nil { if err != nil {
return err return err
} }
defer outFile.Close() defer outFile.Close()
return cmd.GenBashCompletion(outFile) return c.GenBashCompletion(outFile)
} }
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag, if it exists. // MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag, if it exists.
func (cmd *Command) MarkFlagRequired(name string) error { func (c *Command) MarkFlagRequired(name string) error {
return MarkFlagRequired(cmd.Flags(), name) return MarkFlagRequired(c.Flags(), name)
} }
// MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag, if it exists. // MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag, if it exists.
func (cmd *Command) MarkPersistentFlagRequired(name string) error { func (c *Command) MarkPersistentFlagRequired(name string) error {
return MarkFlagRequired(cmd.PersistentFlags(), name) return MarkFlagRequired(c.PersistentFlags(), name)
} }
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists. // MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag in the flag set, if it exists.
@ -508,20 +508,20 @@ func MarkFlagRequired(flags *pflag.FlagSet, name string) error {
// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag, if it exists. // MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided. // Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.
func (cmd *Command) MarkFlagFilename(name string, extensions ...string) error { func (c *Command) MarkFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(cmd.Flags(), name, extensions...) return MarkFlagFilename(c.Flags(), name, extensions...)
} }
// MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. // MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists.
// Generated bash autocompletion will call the bash function f for the flag. // Generated bash autocompletion will call the bash function f for the flag.
func (cmd *Command) MarkFlagCustom(name string, f string) error { func (c *Command) MarkFlagCustom(name string, f string) error {
return MarkFlagCustom(cmd.Flags(), name, f) return MarkFlagCustom(c.Flags(), name, f)
} }
// MarkPersistentFlagFilename adds the BashCompFilenameExt annotation to the named persistent flag, if it exists. // MarkPersistentFlagFilename adds the BashCompFilenameExt annotation to the named persistent flag, if it exists.
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided. // Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.
func (cmd *Command) MarkPersistentFlagFilename(name string, extensions ...string) error { func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {
return MarkFlagFilename(cmd.PersistentFlags(), name, extensions...) return MarkFlagFilename(c.PersistentFlags(), name, extensions...)
} }
// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag in the flag set, if it exists. // MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag in the flag set, if it exists.

View File

@ -9,24 +9,24 @@ import (
) )
// GenZshCompletionFile generates zsh completion file. // GenZshCompletionFile generates zsh completion file.
func (cmd *Command) GenZshCompletionFile(filename string) error { func (c *Command) GenZshCompletionFile(filename string) error {
outFile, err := os.Create(filename) outFile, err := os.Create(filename)
if err != nil { if err != nil {
return err return err
} }
defer outFile.Close() defer outFile.Close()
return cmd.GenZshCompletion(outFile) return c.GenZshCompletion(outFile)
} }
// GenZshCompletion generates a zsh completion file and writes to the passed writer. // GenZshCompletion generates a zsh completion file and writes to the passed writer.
func (cmd *Command) GenZshCompletion(w io.Writer) error { func (c *Command) GenZshCompletion(w io.Writer) error {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
writeHeader(buf, cmd) writeHeader(buf, c)
maxDepth := maxDepth(cmd) maxDepth := maxDepth(c)
writeLevelMapping(buf, maxDepth) writeLevelMapping(buf, maxDepth)
writeLevelCases(buf, maxDepth, cmd) writeLevelCases(buf, maxDepth, c)
_, err := buf.WriteTo(w) _, err := buf.WriteTo(w)
return err return err