Add a -f option to generate registration
Because changes to the registration file require a restart of the matrix server changes to it should be minimized. Therefore, if generate-registration is ran while the file exists, we error out unless the --force/-f option is specified.
This commit is contained in:
@@ -2,6 +2,7 @@ package registration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/appservice"
|
||||||
@@ -12,9 +13,17 @@ import (
|
|||||||
|
|
||||||
type Cmd struct {
|
type Cmd struct {
|
||||||
Filename string `kong:"flag,help='The filename to store the registration into',name='REGISTRATION',short='r',default='registration.yaml'"`
|
Filename string `kong:"flag,help='The filename to store the registration into',name='REGISTRATION',short='r',default='registration.yaml'"`
|
||||||
|
Force bool `kong:"flag,help='Overwrite an existing registration file if it already exists',short='f',default='0'"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cmd) Run(g *globals.Globals) error {
|
func (c *Cmd) Run(g *globals.Globals) error {
|
||||||
|
// Check if the file exists before blinding overwriting it.
|
||||||
|
if _, err := os.Stat(c.Filename); err == nil {
|
||||||
|
if c.Force == false {
|
||||||
|
return fmt.Errorf("file %q exists, use -f to overwrite", c.Filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cfg, err := config.FromFile(g.Config)
|
cfg, err := config.FromFile(g.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user