linter fixes

code cleanup
changing some test code to ensure uniformity
This commit is contained in:
Ajitem Sahasrabuddhe
2019-08-07 20:14:50 +05:30
parent 521735b760
commit fdba7e0f8c
13 changed files with 303 additions and 324 deletions

43
app.go
View File

@@ -11,9 +11,10 @@ import (
)
var (
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
// unused variable. commented for now. will remove in future if agreed upon by everyone
//runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)
contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."
@@ -138,7 +139,7 @@ func (a *App) Setup() {
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
}
newCmds := []Command{}
var newCmds []Command
for _, c := range a.Commands {
if c.HelpName == "" {
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
@@ -197,8 +198,8 @@ func (a *App) Run(arguments []string) (err error) {
nerr := normalizeFlags(a.Flags, set)
context := NewContext(a, set, nil)
if nerr != nil {
fmt.Fprintln(a.Writer, nerr)
ShowAppHelp(context)
_, _ = fmt.Fprintln(a.Writer, nerr)
_ = ShowAppHelp(context)
return nerr
}
context.shellComplete = shellComplete
@@ -213,13 +214,13 @@ func (a *App) Run(arguments []string) (err error) {
a.handleExitCoder(context, err)
return err
}
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
ShowAppHelp(context)
_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
_ = ShowAppHelp(context)
return err
}
if !a.HideHelp && checkHelp(context) {
ShowAppHelp(context)
_ = ShowAppHelp(context)
return nil
}
@@ -230,7 +231,7 @@ func (a *App) Run(arguments []string) (err error) {
cerr := checkRequiredFlags(a.Flags, context)
if cerr != nil {
ShowAppHelp(context)
_ = ShowAppHelp(context)
return cerr
}
@@ -249,8 +250,8 @@ func (a *App) Run(arguments []string) (err error) {
if a.Before != nil {
beforeErr := a.Before(context)
if beforeErr != nil {
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
ShowAppHelp(context)
_, _ = fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
_ = ShowAppHelp(context)
a.handleExitCoder(context, beforeErr)
err = beforeErr
return err
@@ -284,7 +285,7 @@ func (a *App) Run(arguments []string) (err error) {
// code in the cli.ExitCoder
func (a *App) RunAndExitOnError() {
if err := a.Run(os.Args); err != nil {
fmt.Fprintln(a.errWriter(), err)
_, _ = fmt.Fprintln(a.errWriter(), err)
OsExiter(1)
}
}
@@ -323,12 +324,12 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
context := NewContext(a, set, ctx)
if nerr != nil {
fmt.Fprintln(a.Writer, nerr)
fmt.Fprintln(a.Writer)
_, _ = fmt.Fprintln(a.Writer, nerr)
_, _ = fmt.Fprintln(a.Writer)
if len(a.Commands) > 0 {
ShowSubcommandHelp(context)
_ = ShowSubcommandHelp(context)
} else {
ShowCommandHelp(ctx, context.Args().First())
_ = ShowCommandHelp(ctx, context.Args().First())
}
return nerr
}
@@ -343,8 +344,8 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
a.handleExitCoder(context, err)
return err
}
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
ShowSubcommandHelp(context)
_, _ = fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
_ = ShowSubcommandHelp(context)
return err
}
@@ -360,7 +361,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
cerr := checkRequiredFlags(a.Flags, context)
if cerr != nil {
ShowSubcommandHelp(context)
_ = ShowSubcommandHelp(context)
return cerr
}
@@ -440,7 +441,7 @@ func (a *App) VisibleCategories() []*CommandCategory {
// VisibleCommands returns a slice of the Commands with Hidden=false
func (a *App) VisibleCommands() []Command {
ret := []Command{}
var ret []Command
for _, command := range a.Commands {
if !command.Hidden {
ret = append(ret, command)