瀏覽代碼

Add a generate-config command

Gary Kramlich 3 年之前
父節點
當前提交
4e074afc64
共有 2 個文件被更改,包括 29 次插入2 次删除
  1. 25 0
      config/cmd.go
  2. 4 2
      main.go

+ 25 - 0
config/cmd.go

@@ -0,0 +1,25 @@
+package config
+
+import (
+	"gitlab.com/beeper/discord/globals"
+)
+
+type Cmd struct {
+	HomeserverAddress string `kong:"arg,help='The url to for the homeserver',required='1'"`
+	Domain            string `kong:"arg,help='The domain for the homeserver',required='1'"`
+}
+
+func (c *Cmd) Run(g *globals.Globals) error {
+	cfg := &Config{
+		Homeserver: homeserver{
+			Address: c.HomeserverAddress,
+			Domain:  c.Domain,
+		},
+	}
+
+	if err := cfg.validate(); err != nil {
+		return err
+	}
+
+	return cfg.Save(g.Config)
+}

+ 4 - 2
main.go

@@ -6,6 +6,7 @@ import (
 
 	"github.com/alecthomas/kong"
 
+	"gitlab.com/beeper/discord/config"
 	"gitlab.com/beeper/discord/consts"
 	"gitlab.com/beeper/discord/globals"
 	"gitlab.com/beeper/discord/registration"
@@ -15,8 +16,9 @@ import (
 var cli struct {
 	globals.Globals
 
-	GenerateRegistration registration.Cmd `kong:"cmd,help='Generate the registration file for synapse and exit'"`
-	Version              version.Cmd      `kong:"cmd,help='Display the version and exit'"`
+	GenerateConfig       config.Cmd       `kong:"cmd,help='Generate the default configuration and exit.'"`
+	GenerateRegistration registration.Cmd `kong:"cmd,help='Generate the registration file for synapse and exit.'"`
+	Version              version.Cmd      `kong:"cmd,help='Display the version and exit.'"`
 }
 
 func main() {