Unverified Commit 7d913737 authored by Minseong Choi's avatar Minseong Choi 💬
Browse files

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.
parent ce0ba76a
Loading
Loading
Loading
Loading
+7 −3
Changes for cmd/felis/migrate.go: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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
	}