{"record":{"id":"1478605eb51bd129","repo":"puppetlabs/puppet","slug":"value0-conflicts-with-value1","errorCode":null,"errorMessage":"--%{value0} conflicts with --%{value1}","messagePattern":"--%(.+?) conflicts with --%(.+?)","errorType":"exception","errorClass":"CommandlineError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/trollop.rb","lineNumber":408,"sourceCode":"        num_params_taken\n      end\n\n      if handle_help_and_version\n        ## check for version and help args\n        raise VersionNeeded if given_args.include? :version\n        raise HelpNeeded if given_args.include? :help\n      end\n\n      ## check constraint satisfaction\n      @constraints.each do |type, syms|\n        constraint_sym = syms.find { |sym| given_args[sym] }\n        next unless constraint_sym\n\n        case type\n        when :depends\n          syms.each { |sym| raise CommandlineError, _(\"--%{value0} requires --%{value1}\") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } unless given_args.include? sym }\n        when :conflicts\n          syms.each { |sym| raise CommandlineError, _(\"--%{value0} conflicts with --%{value1}\") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } if given_args.include?(sym) && (sym != constraint_sym) }\n        end\n      end\n\n      required.each do |sym, _val|\n        raise CommandlineError, _(\"option --%{opt} must be specified\") % { opt: @specs[sym][:long] } unless given_args.include? sym\n      end\n\n      ## parse parameters\n      given_args.each do |sym, given_data|\n        arg = given_data[:arg]\n        params = given_data[:params]\n\n        opts = @specs[sym]\n        raise CommandlineError, _(\"option '%{arg}' needs a parameter\") % { arg: arg } if params.empty? && opts[:type] != :flag\n\n        vals[\"#{sym}_given\".intern] = true # mark argument as specified on the commandline\n\n        case opts[:type]","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/trollop.rb#L390-L426","documentation":"Constraints registered with conflicts(*syms) are evaluated at trollop.rb:408: when two different members of a conflicts group were both given on the command line, parse raises CommandlineError '--x conflicts with --y'. The check only fires when at least one member was actually supplied — mutually exclusive options that merely have defaults never conflict, and giving the same option twice is caught earlier by the multiple-times check.","triggerScenarios":"A tool that declared `conflicts :xml, :json` invoked as `mytool --xml --json`; combining an alias flag with the flag it aliases when both sit in one conflicts group.","commonSituations":"Mutually exclusive output formats or execution modes (verbose/quiet, dry-run/apply); users chaining flags taken from different examples or recipes.","solutions":["Remove one of the two conflicting flags named in the message","Pick the single mode or format you actually want","As the developer, replace conflicting booleans with one enumerated option (e.g. `--format xml|json`)"],"exampleFix":"# before (tool declared conflicts :xml, :json)\n$ mytool --xml --json\nError: --xml conflicts with --json\n\n# after\n$ mytool --xml","handlingStrategy":"try-catch","validationCode":"# Check conflicts groups before parse\nconstraints = parser.instance_variable_get(:@constraints)\ngiven = argv.map { |t| t[/^--no-?(.+)/, 1]&.tr('-', '_')&.to_sym }.compact\nconstraints.select { |type, _| type == :conflicts }.each do |_, syms|\n  both = syms & given\n  abort \"Mutually exclusive options: --#{both.map { |s| s.to_s.tr('_', '-') }.join(' --')}\" if both.size > 1\nend","typeGuard":null,"tryCatchPattern":"begin\n  opts = parser.parse(argv)\nrescue Puppet::Util::CommandLine::Trollop::CommandlineError => e\n  raise unless e.message.include?(' conflicts with --')\n  loser = e.message[/^--(.+?) conflicts/, 1]\n  warn \"#{e.message} - dropping --#{loser} and keeping the explicit choice\"\n  opts = parser.parse(argv.reject { |t| t == \"--#{loser}\" })\nend","preventionTips":["Give users a single enumerated option (e.g. --format xml|json) instead of conflicting booleans","Read --help for exclusivity notes before combining mode flags","When chaining flags from different examples, check that they do not sit in one conflicts group"],"tags":["puppet","trollop","cli","option-parsing","constraints"],"backgroundTag":"conflicting-cli-options","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}