ソースを参照

fix: add default config var to kong

ayntgl 4 年 前
コミット
60a720f0c5
2 ファイル変更8 行追加4 行削除
  1. 1 3
      config/pkg.go
  2. 7 1
      main.go

+ 1 - 3
config/pkg.go

@@ -9,7 +9,7 @@ import (
 
 type Config struct {
 	Token  string `toml:"-" name:"token" help:"The authentication token." short:"T"`
-	Config string `toml:"-" name:"config" help:"The path of the configuration file." type:"path" short:"C"`
+	Config string `toml:"-" name:"config" help:"The path of the configuration file." default:"${config}" type:"path" short:"C"`
 
 	General GeneralConfig `toml:"general" kong:"-"`
 	Theme   ThemeConfig   `toml:"theme" kong:"-"`
@@ -18,8 +18,6 @@ type Config struct {
 
 func New() *Config {
 	return &Config{
-		Config: DefaultPath(),
-
 		General: newGeneralConfig(),
 		Theme:   newThemeConfig(),
 		Keys:    newKeysConfig(),

+ 7 - 1
main.go

@@ -14,7 +14,13 @@ const name = "discordo"
 
 func main() {
 	cfg := config.New()
-	kong.Parse(cfg, kong.Name(name), kong.UsageOnError())
+	kong.Parse(cfg,
+		kong.Name(name),
+		kong.UsageOnError(),
+		kong.Vars{
+			"config": config.DefaultPath(),
+		},
+	)
 
 	if cfg.Token == "" {
 		cfg.Token, _ = keyring.Get(name, "token")