From 20df7b6a19fc732b3c24d83f015035911b6bd1b3 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 4 Mar 2014 17:01:58 -0800 Subject: [PATCH] feat(version): Print binary version when given --version flag --- coreos-cloudinit.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index 7499383..bbaf36e 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -1,17 +1,24 @@ package main import ( + "fmt" "flag" "io/ioutil" + "os" "log" "github.com/coreos/coreos-cloudinit/cloudinit" ) +const version = "0.1.0+git" + func main() { var userdata []byte var err error + var printVersion bool + flag.BoolVar(&printVersion, "version", false, "Print the version and exit") + var file string flag.StringVar(&file, "from-file", "", "Read user-data from file rather than metadata service") @@ -20,6 +27,11 @@ func main() { flag.Parse() + if printVersion == true { + fmt.Printf("coreos-cloudinit version %s\n", version) + os.Exit(0) + } + if file != "" { log.Printf("Reading user-data from file: %s", file) userdata, err = ioutil.ReadFile(file)