Printing out version numbers

main
Jeremy Saenz 11 years ago
parent 04490dabec
commit d8cf49f0dd

@ -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]

@ -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…
Cancel
Save