Add a force option to the generate-config command

This commit is contained in:
Gary Kramlich
2021-11-20 03:33:19 -06:00
parent 79713cf0ef
commit f97da27731

View File

@@ -1,15 +1,26 @@
package config package config
import ( import (
"fmt"
"os"
"gitlab.com/beeper/discord/globals" "gitlab.com/beeper/discord/globals"
) )
type Cmd struct { type Cmd struct {
HomeserverAddress string `kong:"arg,help='The url to for the homeserver',required='1'"` 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'"` 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 { 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{ cfg := &Config{
Homeserver: homeserver{ Homeserver: homeserver{
Address: c.HomeserverAddress, Address: c.HomeserverAddress,