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:
flyemoji committed 2026-06-27 00:40:38 +09:00
1 parent ce0ba76a3e
commit 7d913737af
1 file changed
+7 -3
+7 -3
View File
@@ -16,11 +16,15 @@ func cmdMigrate(args []string, stdout, stderr io.Writer) int {
fs := flag.NewFlagSet("migrate", flag.ContinueOnError)
fs.SetOutput(stderr)
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
}
if fs.Arg(0) != "up" {
fmt.Fprintln(stderr, "usage: felis migrate up [-config path]")
if err := fs.Parse(args[1:]); err != nil {
return 2
}