{"record":{"id":"ab3e029ee85ce7e3","repo":"urfave/cli","slug":"cannot-set-both-flags-s-and-s","errorCode":null,"errorMessage":"cannot set both flags `--%s` and `--%s`","messagePattern":"cannot set both flags `--(.+?)` and `--(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"flag_bool_with_inverse.go","lineNumber":126,"sourceCode":"\t\t\t}\n\n\t\t\tbif.hasBeenSet = true\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (bif *BoolWithInverseFlag) Set(name, val string) error {\n\tif bif.count > 0 && bif.OnlyOnce {\n\t\treturn fmt.Errorf(\"can't duplicate this flag\")\n\t}\n\n\tbif.hasBeenSet = true\n\n\tif slices.Contains(append([]string{bif.Name}, bif.Aliases...), name) {\n\t\tif bif.nset {\n\t\t\treturn fmt.Errorf(\"cannot set both flags `--%s` and `--%s`\", bif.Name, bif.inversePrefix()+bif.Name)\n\t\t}\n\t\tif err := bif.value.Set(val); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tbif.pset = true\n\t} else {\n\t\tif bif.pset {\n\t\t\treturn fmt.Errorf(\"cannot set both flags `--%s` and `--%s`\", bif.Name, bif.inversePrefix()+bif.Name)\n\t\t}\n\t\tif err := bif.value.Set(\"false\"); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tbif.nset = true\n\t}\n\n\tif bif.Validator != nil {\n\t\treturn bif.Validator(bif.value.Get().(bool))\n\t}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/flag_bool_with_inverse.go#L108-L144","documentation":"BoolWithInverseFlag is a boolean flag that also accepts a negated form (--no-<name> via InversePrefix, default \"no-\"). During Set, if the positive form (Name or an alias) is being applied but the negative form was already set (bif.nset), the library refuses to apply both, since a bool cannot be simultaneously true and false. This is thrown from the positive-set branch of BoolWithInverseFlag.Set.","triggerScenarios":"The user passes both the positive and negative forms on the command line, e.g. `--verbose --no-verbose`, or an alias plus the negated name (e.g. `--v --no-verbose`). Also occurs when a source (env/file via Sources) sets the inverse value first and then the positive flag is parsed, since PostParse calls Set for external sources too.","commonSituations":"Shell aliases or wrapper scripts that append --no-X while the user also types --X; conflicting environment variables resolved through Sources; copy-pasted command lines where a negation was left in accidentally.","solutions":["Remove one of the two conflicting flags from the command line — keep either --name or --no-name, not both.","Check the flag's Sources (env vars, config files) to make sure an external source is not already setting the inverse form before the CLI argument is applied.","If both forms must be tolerated, use a plain BoolFlag instead of BoolWithInverseFlag, which has no mutual-exclusion check.","Inspect scripts/aliases that prepend flags (e.g. a Makefile or wrapper adding --no-X) and reconcile with user-supplied flags."],"exampleFix":"// before\nmyapp --verbose --no-verbose\n\n// after\nmyapp --verbose   # or: myapp --no-verbose","handlingStrategy":"validation","validationCode":"// shell pre-check before invoking the app\nargs=(\"$@\")\npos=$(printf '%s\\n' \"${args[@]}\" | grep -c -- '--verbose$' || true)\nneg=$(printf '%s\\n' \"${args[@]}\" | grep -c -- '--no-verbose$' || true)\nif [ \"$pos\" -gt 0 ] && [ \"$neg\" -gt 0 ]; then echo \"conflict: use --verbose OR --no-verbose\" >&2; exit 1; fi","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(ctx, os.Args); err != nil {\n    if strings.Contains(err.Error(), \"cannot set both flags\") {\n        fmt.Fprintln(os.Stderr, \"conflicting bool flag forms; pick one of --name / --no-name\")\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Never combine --name and --no-<name> in one invocation.","Audit wrapper scripts/aliases for hardcoded negation flags.","Keep env-var Sources consistent with the CLI form of the flag.","Document the inverse prefix (default no-) for your flag's users."],"tags":["cli","flags","conflicting-arguments","go"],"backgroundTag":"conflicting-flag-values","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}