cmd.go 784 B

123456789101112131415161718192021222324252627282930313233343536
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "go.mau.fi/mautrix-discord/globals"
  6. )
  7. type Cmd struct {
  8. HomeserverAddress string `kong:"arg,help='The url to for the homeserver',required='1'"`
  9. Domain string `kong:"arg,help='The domain for the homeserver',required='1'"`
  10. Force bool `kong:"flag,help='Overwrite an existing configuration file if one already exists',short='f',default='0'"`
  11. }
  12. func (c *Cmd) Run(g *globals.Globals) error {
  13. if _, err := os.Stat(g.Config); err == nil {
  14. if c.Force == false {
  15. return fmt.Errorf("file %q exists, use -f to overwrite", g.Config)
  16. }
  17. }
  18. cfg := &Config{
  19. Homeserver: homeserver{
  20. Address: c.HomeserverAddress,
  21. Domain: c.Domain,
  22. },
  23. }
  24. if err := cfg.validate(); err != nil {
  25. return err
  26. }
  27. return cfg.Save(g.Config)
  28. }