app, help: add backwards compatibility for Authors
This commit is contained in:
parent
05ecd63a95
commit
c6592bb487
14
app.go
14
app.go
@ -40,8 +40,12 @@ type App struct {
|
|||||||
CommandNotFound func(context *Context, command string)
|
CommandNotFound func(context *Context, command string)
|
||||||
// Compilation date
|
// Compilation date
|
||||||
Compiled time.Time
|
Compiled time.Time
|
||||||
// Authors
|
// List of all authors who contributed
|
||||||
Authors []Author
|
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 writer to write output to
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
}
|
}
|
||||||
@ -65,6 +69,8 @@ func NewApp() *App {
|
|||||||
BashComplete: DefaultAppComplete,
|
BashComplete: DefaultAppComplete,
|
||||||
Action: helpCommand.Action,
|
Action: helpCommand.Action,
|
||||||
Compiled: compileTime(),
|
Compiled: compileTime(),
|
||||||
|
Author: "Dr. James",
|
||||||
|
Email: "who@gmail.com",
|
||||||
Authors: []Author{{"Jim", "jim@corporate.com"}, {"Hank", "hank@indiepalace.com"}},
|
Authors: []Author{{"Jim", "jim@corporate.com"}, {"Hank", "hank@indiepalace.com"}},
|
||||||
Writer: os.Stdout,
|
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
|
// 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 {
|
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 {
|
if HelpPrinter == nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
HelpPrinter = nil
|
HelpPrinter = nil
|
||||||
@ -281,7 +291,7 @@ type Author struct {
|
|||||||
func (a Author) String() string {
|
func (a Author) String() string {
|
||||||
e := ""
|
e := ""
|
||||||
if a.Email != "" {
|
if a.Email != "" {
|
||||||
e = " <" + a.Email + "> "
|
e = "<" + a.Email + "> "
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%v %v", a.Name, e)
|
return fmt.Sprintf("%v %v", a.Name, e)
|
||||||
|
@ -21,8 +21,9 @@ func ExampleApp() {
|
|||||||
app.Action = func(c *cli.Context) {
|
app.Action = func(c *cli.Context) {
|
||||||
fmt.Printf("Hello %v\n", c.String("name"))
|
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.Authors = []cli.Author{{"Oliver Allen", "oliver@toyshop.com"}}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// Hello Jeremy
|
// Hello Jeremy
|
||||||
|
3
help.go
3
help.go
@ -14,7 +14,8 @@ USAGE:
|
|||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}
|
{{.Version}}
|
||||||
|
|
||||||
AUTHOR(S): {{range .Authors}} {{ . }}{{end}}
|
AUTHOR(S):
|
||||||
|
{{range .Authors}}{{ . }} {{end}}
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
|
||||||
|
Loading…
Reference in New Issue
Block a user