Add version flag to display current version

This commit is contained in:
2026-03-04 17:52:11 +01:00
parent e933219b94
commit f10c0b03bf
2 changed files with 10 additions and 7 deletions

View File

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

View File

@@ -6,7 +6,8 @@ import (
) )
func main() { func main() {
c := config.LoadConfig() applicationVersion := "0.0.0"
c := config.LoadConfig(applicationVersion)
r := setup.Setup(&c) r := setup.Setup(&c)
r.Run(":" + c.Port) r.Run(":" + c.Port)
} }