From c1a4e30bbd7c215ef330910d0a151cd58853472b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 26 Jan 2018 18:21:40 -0800 Subject: [PATCH 1/2] Add --version flag This is useful to get the version from the compiled binary without the need to run it --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 2effd3671..f788eab83 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "github.com/cloudflare/unsee/internal/config" "github.com/cloudflare/unsee/internal/models" "github.com/cloudflare/unsee/internal/transform" + "github.com/spf13/pflag" "github.com/DeanThompson/ginpprof" "github.com/gin-contrib/gzip" @@ -109,6 +110,13 @@ func setupLogger() { } func main() { + printVersion := pflag.Bool("version", false, "Print version and exit") + pflag.Parse() + if *printVersion { + fmt.Println(version) + return + } + config.Config.Read() setupLogger() From 193c6cf3724d6f1652add819ed77b1d4cf8c58c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Fri, 26 Jan 2018 18:21:57 -0800 Subject: [PATCH 2/2] Drop duplicated pflag.Parse call --- internal/config/config.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 268b3e7c7..55c63fab0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -79,8 +79,6 @@ func init() { func (config *configSchema) Read() { v := viper.New() - pflag.Parse() - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() v.BindPFlags(pflag.CommandLine)