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 (
"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

View File

@@ -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)
}