From e2cfb2d70c8b56c414d8308a64c2768fd8ed268c Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Wed, 5 Jun 2019 16:28:59 -0700 Subject: [PATCH] Add a -v flag to print version information --- cmd/blog/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/blog/main.go b/cmd/blog/main.go index f0647e1..0624ca9 100644 --- a/cmd/blog/main.go +++ b/cmd/blog/main.go @@ -27,6 +27,7 @@ var ( var ( fDebug bool fAddress string + fVersion bool ) func init() { @@ -34,11 +35,17 @@ func init() { flag.BoolVar(&fDebug, "d", false, "Debug mode (alias)") flag.StringVar(&fAddress, "address", ":8000", "Bind address") flag.StringVar(&fAddress, "a", ":8000", "Bind address (alias)") + flag.BoolVar(&fVersion, "v", false, "Print version info and quit") rand.Seed(time.Now().UnixNano()) } func main() { flag.Parse() + if fVersion { + fmt.Printf("This is blog v%s build %s", Version, Build) + return + } + userRoot := flag.Arg(0) if userRoot == "" { fmt.Printf("Need user root\n")