Prefer fmt.Fprint* functions over io.WriteString
Less composition needed.
This commit is contained in:
16
app.go
16
app.go
@@ -112,18 +112,18 @@ func (a *App) Run(arguments []string) error {
|
||||
err := set.Parse(arguments[1:])
|
||||
nerr := normalizeFlags(a.Flags, set)
|
||||
if nerr != nil {
|
||||
io.WriteString(a.Writer, fmt.Sprintln(nerr))
|
||||
fmt.Fprintln(a.Writer, nerr)
|
||||
context := NewContext(a, set, set)
|
||||
ShowAppHelp(context)
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(a.Writer)
|
||||
return nerr
|
||||
}
|
||||
context := NewContext(a, set, set)
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(a.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
||||
ShowAppHelp(context)
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(a.Writer)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (a *App) Run(arguments []string) error {
|
||||
// Another entry point to the cli app, takes care of passing arguments and error handling
|
||||
func (a *App) RunAndExitOnError() {
|
||||
if err := a.Run(os.Args); err != nil {
|
||||
os.Stderr.WriteString(fmt.Sprintln(err))
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -191,18 +191,18 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
|
||||
context := NewContext(a, set, ctx.globalSet)
|
||||
|
||||
if nerr != nil {
|
||||
io.WriteString(a.Writer, fmt.Sprintln(nerr))
|
||||
fmt.Fprintln(a.Writer, nerr)
|
||||
if len(a.Commands) > 0 {
|
||||
ShowSubcommandHelp(context)
|
||||
} else {
|
||||
ShowCommandHelp(ctx, context.Args().First())
|
||||
}
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(a.Writer)
|
||||
return nerr
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(a.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
fmt.Fprintf(a.Writer, "Incorrect Usage.\n\n")
|
||||
ShowSubcommandHelp(context)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user