{"record":{"id":"b8d84e8122aa23b4","repo":"golang-migrate/migrate","slug":"all-cannot-be-used-with-other-arguments","errorCode":null,"errorMessage":"-all cannot be used with other arguments","messagePattern":"-all cannot be used with other arguments","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/commands.go","lineNumber":230,"sourceCode":"func versionCmd(m *migrate.Migrate) error {\n\tv, dirty, err := m.Version()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif dirty {\n\t\tlog.Printf(\"%v (dirty)\\n\", v)\n\t} else {\n\t\tlog.Println(v)\n\t}\n\treturn nil\n}\n\n// numDownMigrationsFromArgs returns an int for number of migrations to apply\n// and a bool indicating if we need a confirm before applying\nfunc numDownMigrationsFromArgs(applyAll bool, args []string) (int, bool, error) {\n\tif applyAll {\n\t\tif len(args) > 0 {\n\t\t\treturn 0, false, errors.New(\"-all cannot be used with other arguments\")\n\t\t}\n\t\treturn -1, false, nil\n\t}\n\n\tswitch len(args) {\n\tcase 0:\n\t\treturn -1, true, nil\n\tcase 1:\n\t\tdownValue := args[0]\n\t\tn, err := strconv.ParseUint(downValue, 10, 64)\n\t\tif err != nil {\n\t\t\treturn 0, false, errors.New(\"can't read limit argument N\")\n\t\t}\n\t\treturn int(n), false, nil\n\tdefault:\n\t\treturn 0, false, errors.New(\"too many arguments\")\n\t}\n}","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/internal/cli/commands.go#L212-L248","documentation":"numDownMigrationsFromArgs returns the error '-all cannot be used with other arguments' when `migrate down -all` is invoked together with an extra positional argument. The -all flag means 'down all migrations' and is therefore incompatible with an explicit limit N; the CLI surfaces this to force an unambiguous command.","triggerScenarios":"Running `migrate -source file -path . down -all 2` — the -all flag combined with one or more positional args (len(args) > 0 when applyAll is true).","commonSituations":"Script templates appending an argument for other subcommands while -all is still present; users unsure whether to use -all or N and passing both; shell variable expansion that appends an empty-but-counted argument.","solutions":["Use `migrate down -all` alone to revert everything, or `migrate down N` without -all to revert N migrations.","Remove the extra positional argument from the command line/script.","Guard in wrapper scripts: if -all is present, drop any positional args.","Check shell variables/quoting so they don't inject an unexpected argument."],"exampleFix":"// before\nmigrate -path ./migrations -database $DB down -all 2\n// after\nmigrate -path ./migrations -database $DB down -all   # or: down 2 without -all","handlingStrategy":"validation","validationCode":"ARGS=$(cat)\nif grep -q -- '-all' <<< \"$ARGS\" && [ $(wc -w <<< \"$POSITIONAL\") -gt 0 ]; then\n\techo \"-all cannot be combined with positional arguments\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose either -all or a count N — never both","Separate flags from positional args in wrapper scripts and drop positionals when -all is set","Read migrate's CLI help for the down subcommand to confirm accepted forms"],"tags":["go","cli","golang-migrate","conflicting-flags"],"backgroundTag":"conflicting-flags","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}