Merge pull request #260 from ianwalter/code-cleanup

Fixing golint warnings
This commit is contained in:
Eric Paris 2016-03-31 09:32:10 -05:00
commit b0d571e7d5
7 changed files with 39 additions and 47 deletions

View file

@ -25,7 +25,7 @@ func check(t *testing.T, found, expected string) {
// World worst custom function, just keep telling you to enter hello!
const (
bash_completion_func = `__custom_func() {
bashCompletionFunc = `__custom_func() {
COMPREPLY=( "hello" )
}
`
@ -37,7 +37,7 @@ func TestBashCompletions(t *testing.T) {
c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon)
// custom completion function
c.BashCompletionFunction = bash_completion_func
c.BashCompletionFunction = bashCompletionFunc
// required flag
c.MarkFlagRequired("introot")

View file

@ -26,7 +26,7 @@ import (
"unicode"
)
var templateFuncs template.FuncMap = template.FuncMap{
var templateFuncs = template.FuncMap{
"trim": strings.TrimSpace,
"trimRightSpace": trimRightSpace,
"appendIfNotPresent": appendIfNotPresent,
@ -39,7 +39,7 @@ var initializers []func()
// automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.
// Set this to true to enable it
var EnablePrefixMatching bool = false
var EnablePrefixMatching = false
//AddTemplateFunc adds a template function that's available to Usage and Help
//template generation.

View file

@ -196,7 +196,7 @@ func isEmpty(path string) (bool, error) {
if err != nil {
return false, err
}
list, err := f.Readdir(-1)
list, _ := f.Readdir(-1)
// f.Close() - see bug fix above
return len(list) == 0, nil
}

View file

@ -454,10 +454,10 @@ func TestGrandChildSameName(t *testing.T) {
func TestUsage(t *testing.T) {
x := fullSetupTest("help")
checkResultContains(t, x, cmdRootWithRun.Use + " [flags]")
checkResultContains(t, x, cmdRootWithRun.Use+" [flags]")
x = fullSetupTest("help customflags")
checkResultContains(t, x, cmdCustomFlags.Use)
checkResultOmits(t, x, cmdCustomFlags.Use + " [flags]")
checkResultOmits(t, x, cmdCustomFlags.Use+" [flags]")
}
func TestFlagLong(t *testing.T) {
@ -752,7 +752,7 @@ func TestVisitParents(t *testing.T) {
}
func TestRunnableRootCommandNilInput(t *testing.T) {
empty_arg := make([]string, 0)
var emptyArg []string
c := initializeWithRootCmd()
buf := new(bytes.Buffer)
@ -760,7 +760,7 @@ func TestRunnableRootCommandNilInput(t *testing.T) {
c.SetOutput(buf)
cmdEcho.AddCommand(cmdTimes)
c.AddCommand(cmdPrint, cmdEcho)
c.SetArgs(empty_arg)
c.SetArgs(emptyArg)
err := c.Execute()
if err != nil {
@ -863,7 +863,7 @@ func TestFlagAccess(t *testing.T) {
}
func TestNoNRunnableRootCommandNilInput(t *testing.T) {
args := make([]string, 0)
var args []string
c := initialize()
buf := new(bytes.Buffer)

View file

@ -132,9 +132,8 @@ func (c *Command) getOut(def io.Writer) io.Writer {
if c.HasParent() {
return c.parent.Out()
} else {
return def
}
return def
}
func (c *Command) Out() io.Writer {
@ -194,7 +193,7 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
if c.HasParent() {
return c.parent.UsageFunc()
} else {
}
return func(c *Command) error {
err := tmpl(c.Out(), c.UsageTemplate(), c)
if err != nil {
@ -202,7 +201,6 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
}
return err
}
}
}
// HelpFunc returns either the function set by SetHelpFunc for this command
@ -223,35 +221,32 @@ func (c *Command) HelpFunc() func(*Command, []string) {
}
}
var minUsagePadding int = 25
var minUsagePadding = 25
func (c *Command) UsagePadding() int {
if c.parent == nil || minUsagePadding > c.parent.commandsMaxUseLen {
return minUsagePadding
} else {
return c.parent.commandsMaxUseLen
}
return c.parent.commandsMaxUseLen
}
var minCommandPathPadding int = 11
var minCommandPathPadding = 11
//
func (c *Command) CommandPathPadding() int {
if c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {
return minCommandPathPadding
} else {
return c.parent.commandsMaxCommandPathLen
}
return c.parent.commandsMaxCommandPathLen
}
var minNamePadding int = 11
var minNamePadding = 11
func (c *Command) NamePadding() int {
if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {
return minNamePadding
} else {
return c.parent.commandsMaxNameLen
}
return c.parent.commandsMaxNameLen
}
func (c *Command) UsageTemplate() string {
@ -261,7 +256,7 @@ func (c *Command) UsageTemplate() string {
if c.HasParent() {
return c.parent.UsageTemplate()
} else {
}
return `Usage:{{if .Runnable}}
{{if .HasFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasSubCommands}}
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
@ -287,7 +282,6 @@ Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
}
}
func (c *Command) HelpTemplate() string {
@ -297,11 +291,10 @@ func (c *Command) HelpTemplate() string {
if c.HasParent() {
return c.parent.HelpTemplate()
} else {
}
return `{{with or .Long .Short }}{{. | trim}}
{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
}
}
// Really only used when casting a command to a commander
@ -603,9 +596,8 @@ func (c *Command) errorMsgFromParse() string {
if len(x) > 0 {
return x[0]
} else {
return ""
}
return ""
}
// Call execute to use the args (os.Args[1:] by default)
@ -786,18 +778,18 @@ main:
}
}
// Convenience method to Print to the defined output
// Print is a convenience method to Print to the defined output
func (c *Command) Print(i ...interface{}) {
fmt.Fprint(c.Out(), i...)
}
// Convenience method to Println to the defined output
// Println is a convenience method to Println to the defined output
func (c *Command) Println(i ...interface{}) {
str := fmt.Sprintln(i...)
c.Print(str)
}
// Convenience method to Printf to the defined output
// Printf is a convenience method to Printf to the defined output
func (c *Command) Printf(format string, i ...interface{}) {
str := fmt.Sprintf(format, i...)
c.Print(str)
@ -908,7 +900,7 @@ func (c *Command) Name() string {
return name
}
// Determine if a given string is an alias of the command.
// HasAlias determines if a given string is an alias of the command.
func (c *Command) HasAlias(s string) bool {
for _, a := range c.Aliases {
if a == s {
@ -926,12 +918,12 @@ func (c *Command) HasExample() bool {
return len(c.Example) > 0
}
// Determine if the command is itself runnable
// Runnable determines if the command is itself runnable
func (c *Command) Runnable() bool {
return c.Run != nil || c.RunE != nil
}
// Determine if the command has children commands
// HasSubCommands determines if the command has children commands
func (c *Command) HasSubCommands() bool {
return len(c.commands) > 0
}
@ -1123,7 +1115,7 @@ func (c *Command) HasInheritedFlags() bool {
return c.InheritedFlags().HasFlags()
}
// Climbs up the command tree looking for matching flag
// Flag climbs up the command tree looking for matching flag
func (c *Command) Flag(name string) (flag *flag.Flag) {
flag = c.Flags().Lookup(name)
@ -1146,13 +1138,14 @@ func (c *Command) persistentFlag(name string) (flag *flag.Flag) {
return
}
// Parses persistent flag tree & local flags
// ParseFlags parses persistent flag tree & local flags
func (c *Command) ParseFlags(args []string) (err error) {
c.mergePersistentFlags()
err = c.Flags().Parse(args)
return
}
// Parent returns a commands parent command
func (c *Command) Parent() *Command {
return c.parent
}

View file

@ -2,4 +2,4 @@
package cobra
var preExecHookFn func(*Command) = nil
var preExecHookFn func(*Command)

View file

@ -149,9 +149,8 @@ func AssertNextLineEquals(scanner *bufio.Scanner, expectedLine string) error {
line := scanner.Text()
if line == expectedLine {
return nil
} else {
return fmt.Errorf("AssertNextLineEquals: got %#v, not %#v", line, expectedLine)
}
return fmt.Errorf("AssertNextLineEquals: got %#v, not %#v", line, expectedLine)
}
if err := scanner.Err(); err != nil {