From f97da27731dc486899c556b0a1576de881b13f52 Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Sat, 20 Nov 2021 03:33:19 -0600 Subject: [PATCH] Add a force option to the generate-config command --- config/cmd.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/cmd.go b/config/cmd.go index 6538678..be5262d 100644 --- a/config/cmd.go +++ b/config/cmd.go @@ -1,15 +1,26 @@ package config import ( + "fmt" + "os" + "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'"` + + Force bool `kong:"flag,help='Overwrite an existing configuration file if one already exists',short='f',default='0'"` } func (c *Cmd) Run(g *globals.Globals) error { + if _, err := os.Stat(g.Config); err == nil { + if c.Force == false { + return fmt.Errorf("file %q exists, use -f to overwrite", g.Config) + } + } + cfg := &Config{ Homeserver: homeserver{ Address: c.HomeserverAddress,