fix(migrate): honor -config flag placed after the up verb
Go's flag.Parse stops at the first non-flag token, so a -config given as 'felis migrate up -config path' was silently dropped and the default path used instead. Pull the up verb off the front, then parse the remaining flags so the configured path is honored.
This commit is contained in:
1 file changed
+7
-3
@@ -16,11 +16,15 @@ func cmdMigrate(args []string, stdout, stderr io.Writer) int {
|
|||||||
fs := flag.NewFlagSet("migrate", flag.ContinueOnError)
|
fs := flag.NewFlagSet("migrate", flag.ContinueOnError)
|
||||||
fs.SetOutput(stderr)
|
fs.SetOutput(stderr)
|
||||||
cfgPath := fs.String("config", "/etc/felis/felis.toml", "path to felis.toml")
|
cfgPath := fs.String("config", "/etc/felis/felis.toml", "path to felis.toml")
|
||||||
if err := fs.Parse(args); err != nil {
|
// The "up" verb precedes any flags (felis migrate up -config path). Go's
|
||||||
|
// flag.Parse stops at the first non-flag token and would never see a flag
|
||||||
|
// placed after "up", silently falling back to the default -config. Pull the
|
||||||
|
// verb off the front, then parse the remaining flags.
|
||||||
|
if len(args) == 0 || args[0] != "up" {
|
||||||
|
fmt.Fprintln(stderr, "usage: felis migrate up [-config path]")
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
if fs.Arg(0) != "up" {
|
if err := fs.Parse(args[1:]); err != nil {
|
||||||
fmt.Fprintln(stderr, "usage: felis migrate up [-config path]")
|
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user