diff --git a/internal/config/config.go b/internal/config/config.go index c6502be..a0a7bfc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "errors" + "fmt" "log" "os" "strings" @@ -13,10 +14,11 @@ import ( ) type CLI struct { - NoConfigFile bool `short:"C" default:"false" help:"Disable config file creation."` - ConfigFilePath string `short:"c" default:"bibliomane.toml" type:"path" help:"Config file path."` - DisableStoreJWTKeyInConfig bool `default:"false" help:"Do not store the generated key used for JWT when initializing configuration."` - ConfigFile Config `embed:"" prefix:""` + Version kong.VersionFlag `short:"v"` + NoConfigFile bool `short:"C" default:"false" help:"Disable config file creation."` + ConfigFilePath string `short:"c" default:"bibliomane.toml" type:"path" help:"Config file path."` + DisableStoreJWTKeyInConfig bool `default:"false" help:"Do not store the generated key used for JWT when initializing configuration."` + ConfigFile Config `embed:"" prefix:""` } type Config struct { @@ -61,12 +63,12 @@ func defaultConfig() CLI { return CLI{NoConfigFile: false, ConfigFilePath: "bibliomane.toml", DisableStoreJWTKeyInConfig: false, ConfigFile: c} } -func LoadConfig() Config { +func LoadConfig(applicationVersion string) Config { var cfg CLI //parse first to get config path - kong.Parse(&cfg) + kong.Parse(&cfg, kong.Vars{"version": fmt.Sprintf("bibliomane v%s", applicationVersion)}) configPath := cfg.ConfigFilePath diff --git a/main.go b/main.go index cf4cb2b..6820b35 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,8 @@ import ( ) func main() { - c := config.LoadConfig() + applicationVersion := "0.0.0" + c := config.LoadConfig(applicationVersion) r := setup.Setup(&c) r.Run(":" + c.Port) }