app, help: add backwards compatibility for Authors

This commit is contained in:
Harrison 2015-02-21 10:44:00 +11:00
parent 05ecd63a95
commit c6592bb487
3 changed files with 16 additions and 4 deletions

12
app.go
View File

@ -40,8 +40,12 @@ type App struct {
CommandNotFound func(context *Context, command string)
// Compilation date
Compiled time.Time
// Authors
// List of all authors who contributed
Authors []Author
// Name of Author (Note: Use App.Authors, this is deprecated)
Author string
// Email of Author (Note: Use App.Authors, this is deprecated)
Email string
// Writer writer to write output to
Writer io.Writer
}
@ -65,6 +69,8 @@ func NewApp() *App {
BashComplete: DefaultAppComplete,
Action: helpCommand.Action,
Compiled: compileTime(),
Author: "Dr. James",
Email: "who@gmail.com",
Authors: []Author{{"Jim", "jim@corporate.com"}, {"Hank", "hank@indiepalace.com"}},
Writer: os.Stdout,
}
@ -72,6 +78,10 @@ func NewApp() *App {
// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
func (a *App) Run(arguments []string) error {
if a.Author != "" && a.Author != "" {
a.Authors = append(a.Authors, Author{a.Author, a.Email})
}
if HelpPrinter == nil {
defer func() {
HelpPrinter = nil

View File

@ -21,8 +21,9 @@ func ExampleApp() {
app.Action = func(c *cli.Context) {
fmt.Printf("Hello %v\n", c.String("name"))
}
app.Author = "Harrison"
app.Email = "harrison@lolwut.com"
app.Authors = []cli.Author{{"Oliver Allen", "oliver@toyshop.com"}}
app.Run(os.Args)
// Output:
// Hello Jeremy

View File

@ -14,7 +14,8 @@ USAGE:
VERSION:
{{.Version}}
AUTHOR(S): {{range .Authors}} {{ . }}{{end}}
AUTHOR(S):
{{range .Authors}}{{ . }} {{end}}
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}