app, help: add support for multiple authors
This commit is contained in:
parent
e1712f3817
commit
3d7183307a
25
app.go
25
app.go
@ -40,10 +40,8 @@ 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
|
||||||
// Author
|
// Authors
|
||||||
Author string
|
Authors []Author
|
||||||
// Author e-mail
|
|
||||||
Email string
|
|
||||||
// Writer writer to write output to
|
// Writer writer to write output to
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
}
|
}
|
||||||
@ -67,8 +65,7 @@ func NewApp() *App {
|
|||||||
BashComplete: DefaultAppComplete,
|
BashComplete: DefaultAppComplete,
|
||||||
Action: helpCommand.Action,
|
Action: helpCommand.Action,
|
||||||
Compiled: compileTime(),
|
Compiled: compileTime(),
|
||||||
Author: "Author",
|
Authors: []Author{{"Jim", "jim@corporate.com"}, {"Hank", "hank@indiepalace.com"}},
|
||||||
Email: "unknown@email",
|
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,3 +270,19 @@ func (a *App) appendFlag(flag Flag) {
|
|||||||
a.Flags = append(a.Flags, flag)
|
a.Flags = append(a.Flags, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Author represents someone who has contributed to a cli project.
|
||||||
|
type Author struct {
|
||||||
|
Name string // The Authors name
|
||||||
|
Email string // The Authors email
|
||||||
|
}
|
||||||
|
|
||||||
|
// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
|
||||||
|
func (a Author) String() string {
|
||||||
|
e := ""
|
||||||
|
if a.Email != "" {
|
||||||
|
e = " <" + a.Email + "> "
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%v %v", a.Name, e)
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/paked/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleApp() {
|
func ExampleApp() {
|
||||||
@ -21,6 +21,8 @@ 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.Authors = []cli.Author{{"Oliver Allen", "oliver@toyshop.com"}}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
// Output:
|
// Output:
|
||||||
// Hello Jeremy
|
// Hello Jeremy
|
||||||
|
6
help.go
6
help.go
@ -12,11 +12,9 @@ USAGE:
|
|||||||
{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
|
{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}{{if or .Author .Email}}
|
{{.Version}}
|
||||||
|
|
||||||
AUTHOR:{{if .Author}}
|
AUTHOR(S): {{range .Authors}} {{ . }}{{end}}
|
||||||
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
|
|
||||||
{{.Email}}{{end}}{{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