Removed error handling and cleaned up template
This commit is contained in:
parent
5b788be8a6
commit
9186f6e81a
32
help.go
32
help.go
@ -1,8 +1,6 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
import "log"
|
|
||||||
|
|
||||||
import "text/tabwriter"
|
import "text/tabwriter"
|
||||||
import "text/template"
|
import "text/template"
|
||||||
|
|
||||||
@ -20,23 +18,20 @@ var HelpCommand = Command{
|
|||||||
Action: ShowHelp,
|
Action: ShowHelp,
|
||||||
}
|
}
|
||||||
|
|
||||||
var helpTemplate = `NAME:
|
var ShowHelp = func(name string) {
|
||||||
{{.Name}} - {{.Usage}}
|
helpTemplate := `NAME:
|
||||||
|
{{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.Name}} [global-options] COMMAND [command-options]
|
{{.Name}} [global options] command [command options] [arguments...]
|
||||||
|
|
||||||
VERSION:
|
VERSION:
|
||||||
{{.Version}}
|
{{.Version}}
|
||||||
|
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{.Name}}{{ "\t" }}{{.Usage}}
|
{{range .Commands}}{{.Name}}{{ "\t" }}{{.Usage}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
var ShowHelp = func(name string) {
|
|
||||||
|
|
||||||
data := HelpData{
|
data := HelpData{
|
||||||
Name,
|
Name,
|
||||||
Usage,
|
Usage,
|
||||||
@ -46,17 +41,6 @@ var ShowHelp = func(name string) {
|
|||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
t := template.Must(template.New("help").Parse(helpTemplate))
|
t := template.Must(template.New("help").Parse(helpTemplate))
|
||||||
err := t.Execute(w, data)
|
t.Execute(w, data)
|
||||||
w.Flush()
|
w.Flush()
|
||||||
if err != nil {
|
|
||||||
log.Println("executing template:", err)
|
|
||||||
}
|
|
||||||
// fmt.Printf("Usage: %v [global-options] COMMAND [command-options]\n\n", Name)
|
|
||||||
// if Commands != nil {
|
|
||||||
// fmt.Printf("The most commonly used %v commands are:\n", Name)
|
|
||||||
// for _, c := range Commands {
|
|
||||||
// fmt.Fprintln(w, " "+c.Name+"\t"+c.Usage)
|
|
||||||
// }
|
|
||||||
// w.Flush()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user