From 4e074afc64da86bdba2f098da609975f6127328b Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Sat, 20 Nov 2021 03:27:46 -0600 Subject: [PATCH] Add a generate-config command --- config/cmd.go | 25 +++++++++++++++++++++++++ main.go | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 config/cmd.go diff --git a/config/cmd.go b/config/cmd.go new file mode 100644 index 0000000..6538678 --- /dev/null +++ b/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) +} diff --git a/main.go b/main.go index 844088a..a740fb8 100644 --- a/main.go +++ b/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() {