Prefer fmt.Fprint* functions over io.WriteString
Less composition needed.
This commit is contained in:
parent
b8c8282de5
commit
e72094e6a4
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
|
||||
}
|
||||
|
11
command.go
11
command.go
@ -2,7 +2,6 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
@ -75,18 +74,18 @@ func (c Command) Run(ctx *Context) error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
fmt.Fprint(ctx.App.Writer, "Incorrect Usage.\n\n")
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(ctx.App.Writer)
|
||||
return err
|
||||
}
|
||||
|
||||
nerr := normalizeFlags(c.Flags, set)
|
||||
if nerr != nil {
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(nerr))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(ctx.App.Writer, nerr)
|
||||
fmt.Fprintln(ctx.App.Writer)
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
fmt.Fprintln(ctx.App.Writer)
|
||||
return nerr
|
||||
}
|
||||
context := NewContext(ctx.App, set, ctx.globalSet)
|
||||
|
13
help.go
13
help.go
@ -1,9 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
// The text template for the Default help topic.
|
||||
// cli.go uses text/template to render templates. You can
|
||||
@ -106,9 +103,9 @@ func ShowAppHelp(c *Context) {
|
||||
// Prints the list of subcommands as the default app completion method
|
||||
func DefaultAppComplete(c *Context) {
|
||||
for _, command := range c.App.Commands {
|
||||
io.WriteString(c.App.Writer, fmt.Sprintln(command.Name))
|
||||
fmt.Fprintln(c.App.Writer, command.Name)
|
||||
if command.ShortName != "" {
|
||||
io.WriteString(c.App.Writer, fmt.Sprintln(command.ShortName))
|
||||
fmt.Fprintln(c.App.Writer, command.ShortName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,7 +122,7 @@ func ShowCommandHelp(c *Context, command string) {
|
||||
if c.App.CommandNotFound != nil {
|
||||
c.App.CommandNotFound(c, command)
|
||||
} else {
|
||||
io.WriteString(c.App.Writer, fmt.Sprintf("No help topic for '%v'\n", command))
|
||||
fmt.Fprintf(c.App.Writer, "No help topic for '%v'\n", command)
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +137,7 @@ func ShowVersion(c *Context) {
|
||||
}
|
||||
|
||||
func printVersion(c *Context) {
|
||||
io.WriteString(c.App.Writer, fmt.Sprintf("%v version %v\n", c.App.Name, c.App.Version))
|
||||
fmt.Fprintf(c.App.Writer, "%v version %v\n", c.App.Name, c.App.Version)
|
||||
}
|
||||
|
||||
// Prints the lists of commands within a given context
|
||||
|
Loading…
Reference in New Issue
Block a user