Add version flag to display current version
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CLI struct {
|
type CLI struct {
|
||||||
|
Version kong.VersionFlag `short:"v"`
|
||||||
NoConfigFile bool `short:"C" default:"false" help:"Disable config file creation."`
|
NoConfigFile bool `short:"C" default:"false" help:"Disable config file creation."`
|
||||||
ConfigFilePath string `short:"c" default:"bibliomane.toml" type:"path" help:"Config file path."`
|
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."`
|
DisableStoreJWTKeyInConfig bool `default:"false" help:"Do not store the generated key used for JWT when initializing configuration."`
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user