Rename Stdout -> Writer
This commit is contained in:
parent
60e3dcaf6d
commit
0d4870d63e
22
app.go
22
app.go
@ -40,8 +40,8 @@ type App struct {
|
||||
Author string
|
||||
// Author e-mail
|
||||
Email string
|
||||
// Stdout writer to write output to
|
||||
Stdout io.Writer
|
||||
// Writer writer to write output to
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
// Tries to find out when this binary was compiled.
|
||||
@ -65,7 +65,7 @@ func NewApp() *App {
|
||||
Compiled: compileTime(),
|
||||
Author: "Author",
|
||||
Email: "unknown@email",
|
||||
Stdout: os.Stdout,
|
||||
Writer: os.Stdout,
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ func (a *App) Run(arguments []string) error {
|
||||
}()
|
||||
|
||||
HelpPrinter = func(templ string, data interface{}) {
|
||||
w := tabwriter.NewWriter(a.Stdout, 0, 8, 1, '\t', 0)
|
||||
w := tabwriter.NewWriter(a.Writer, 0, 8, 1, '\t', 0)
|
||||
t := template.Must(template.New("help").Parse(templ))
|
||||
err := t.Execute(w, data)
|
||||
if err != nil {
|
||||
@ -105,18 +105,18 @@ func (a *App) Run(arguments []string) error {
|
||||
err := set.Parse(arguments[1:])
|
||||
nerr := normalizeFlags(a.Flags, set)
|
||||
if nerr != nil {
|
||||
io.WriteString(a.Stdout, fmt.Sprintln(nerr))
|
||||
io.WriteString(a.Writer, fmt.Sprintln(nerr))
|
||||
context := NewContext(a, set, set)
|
||||
ShowAppHelp(context)
|
||||
io.WriteString(a.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
return nerr
|
||||
}
|
||||
context := NewContext(a, set, set)
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(a.Stdout, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
io.WriteString(a.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
ShowAppHelp(context)
|
||||
io.WriteString(a.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -176,18 +176,18 @@ func (a *App) RunAsSubcommand(ctx *Context) error {
|
||||
context := NewContext(a, set, set)
|
||||
|
||||
if nerr != nil {
|
||||
io.WriteString(a.Stdout, fmt.Sprintln(nerr))
|
||||
io.WriteString(a.Writer, fmt.Sprintln(nerr))
|
||||
if len(a.Commands) > 0 {
|
||||
ShowSubcommandHelp(context)
|
||||
} else {
|
||||
ShowCommandHelp(ctx, context.Args().First())
|
||||
}
|
||||
io.WriteString(a.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(a.Writer, fmt.Sprintln(""))
|
||||
return nerr
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(a.Stdout, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
io.WriteString(a.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
ShowSubcommandHelp(context)
|
||||
return err
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ func TestApp_ParseSliceFlags(t *testing.T) {
|
||||
func TestApp_DefaultStdout(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
|
||||
if app.Stdout != os.Stdout {
|
||||
if app.Writer != os.Stdout {
|
||||
t.Error("Default output writer not set.")
|
||||
}
|
||||
}
|
||||
@ -293,7 +293,7 @@ func TestApp_SetStdout(t *testing.T) {
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "test"
|
||||
app.Stdout = mockWriter
|
||||
app.Writer = mockWriter
|
||||
|
||||
err := app.Run([]string{"help"})
|
||||
|
||||
|
10
command.go
10
command.go
@ -71,18 +71,18 @@ func (c Command) Run(ctx *Context) error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
io.WriteString(ctx.App.Stdout, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintf("Incorrect Usage.\n\n"))
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
return err
|
||||
}
|
||||
|
||||
nerr := normalizeFlags(c.Flags, set)
|
||||
if nerr != nil {
|
||||
io.WriteString(ctx.App.Stdout, fmt.Sprintln(nerr))
|
||||
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(nerr))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
|
||||
io.WriteString(ctx.App.Writer, fmt.Sprintln(""))
|
||||
return nerr
|
||||
}
|
||||
context := NewContext(ctx.App, set, ctx.globalSet)
|
||||
|
8
help.go
8
help.go
@ -99,9 +99,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.Stdout, fmt.Sprintln(command.Name))
|
||||
io.WriteString(c.App.Writer, fmt.Sprintln(command.Name))
|
||||
if command.ShortName != "" {
|
||||
io.WriteString(c.App.Stdout, fmt.Sprintln(command.ShortName))
|
||||
io.WriteString(c.App.Writer, fmt.Sprintln(command.ShortName))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,7 @@ func ShowCommandHelp(c *Context, command string) {
|
||||
if c.App.CommandNotFound != nil {
|
||||
c.App.CommandNotFound(c, command)
|
||||
} else {
|
||||
io.WriteString(c.App.Stdout, fmt.Sprintf("No help topic for '%v'\n", command))
|
||||
io.WriteString(c.App.Writer, fmt.Sprintf("No help topic for '%v'\n", command))
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ func ShowSubcommandHelp(c *Context) {
|
||||
|
||||
// Prints the version number of the App
|
||||
func ShowVersion(c *Context) {
|
||||
io.WriteString(c.App.Stdout, fmt.Sprintf("%v version %v\n", c.App.Name, c.App.Version))
|
||||
io.WriteString(c.App.Writer, fmt.Sprintf("%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