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) {
|
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
|
// parse flags
|
||||||
set := flagSet(a.Name, a.Flags)
|
set := flagSet(a.Name, a.Flags)
|
||||||
set.Parse(arguments[1:])
|
set.Parse(arguments[1:])
|
||||||
|
|
||||||
// append help to commands
|
|
||||||
a.Commands = append(a.Commands, helpCommand)
|
|
||||||
|
|
||||||
context := NewContext(a, set, set)
|
context := NewContext(a, set, set)
|
||||||
|
|
||||||
|
// check version
|
||||||
|
if context.GlobalBool("version") {
|
||||||
|
showVersion(context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
args := context.Args()
|
args := context.Args()
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
13
help.go
13
help.go
@ -1,8 +1,11 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
import "text/tabwriter"
|
"fmt"
|
||||||
import "text/template"
|
"os"
|
||||||
|
"text/tabwriter"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
var helpCommand = Command{
|
var helpCommand = Command{
|
||||||
Name: "help",
|
Name: "help",
|
||||||
@ -32,3 +35,7 @@ GLOBAL OPTIONS:
|
|||||||
w.Flush()
|
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