Printing out version numbers
This commit is contained in:
parent
04490dabec
commit
d8cf49f0dd
15
app.go
15
app.go
@ -28,14 +28,23 @@ func NewApp() *App {
|
||||
}
|
||||
|
||||
func (a *App) Run(arguments []string) {
|
||||
// append help to commands
|
||||
a.Commands = append(a.Commands, helpCommand)
|
||||
// append version to flags
|
||||
a.Flags = append(a.Flags, BoolFlag{"version", "print the version"})
|
||||
|
||||
// parse flags
|
||||
set := flagSet(a.Name, a.Flags)
|
||||
set.Parse(arguments[1:])
|
||||
|
||||
// append help to commands
|
||||
a.Commands = append(a.Commands, helpCommand)
|
||||
|
||||
context := NewContext(a, set, set)
|
||||
|
||||
// check version
|
||||
if context.GlobalBool("version") {
|
||||
showVersion(context)
|
||||
return
|
||||
}
|
||||
|
||||
args := context.Args()
|
||||
if len(args) > 0 {
|
||||
name := args[0]
|
||||
|
13
help.go
13
help.go
@ -1,8 +1,11 @@
|
||||
package cli
|
||||
|
||||
import "os"
|
||||
import "text/tabwriter"
|
||||
import "text/template"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var helpCommand = Command{
|
||||
Name: "help",
|
||||
@ -32,3 +35,7 @@ GLOBAL OPTIONS:
|
||||
w.Flush()
|
||||
},
|
||||
}
|
||||
|
||||
func showVersion(c *Context) {
|
||||
fmt.Printf("%v version %v\n", c.App.Name, c.App.Version)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user