puppetlabs/puppet · error · CommandlineError
--%{value0} conflicts with --%{value1}
Error message
--%{value0} conflicts with --%{value1} What it means
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.
Source
Thrown at lib/puppet/util/command_line/trollop.rb:408
num_params_taken
end
if handle_help_and_version
## check for version and help args
raise VersionNeeded if given_args.include? :version
raise HelpNeeded if given_args.include? :help
end
## check constraint satisfaction
@constraints.each do |type, syms|
constraint_sym = syms.find { |sym| given_args[sym] }
next unless constraint_sym
case type
when :depends
syms.each { |sym| raise CommandlineError, _("--%{value0} requires --%{value1}") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } unless given_args.include? sym }
when :conflicts
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) }
end
end
required.each do |sym, _val|
raise CommandlineError, _("option --%{opt} must be specified") % { opt: @specs[sym][:long] } unless given_args.include? sym
end
## parse parameters
given_args.each do |sym, given_data|
arg = given_data[:arg]
params = given_data[:params]
opts = @specs[sym]
raise CommandlineError, _("option '%{arg}' needs a parameter") % { arg: arg } if params.empty? && opts[:type] != :flag
vals["#{sym}_given".intern] = true # mark argument as specified on the commandline
case opts[:type]View on GitHub (pinned to e227c27540)
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`)
Example fix
# before (tool declared conflicts :xml, :json) $ mytool --xml --json Error: --xml conflicts with --json # after $ mytool --xml
Defensive patterns
Strategy: try-catch
Validate before calling
# Check conflicts groups before parse
constraints = parser.instance_variable_get(:@constraints)
given = argv.map { |t| t[/^--no-?(.+)/, 1]&.tr('-', '_')&.to_sym }.compact
constraints.select { |type, _| type == :conflicts }.each do |_, syms|
both = syms & given
abort "Mutually exclusive options: --#{both.map { |s| s.to_s.tr('_', '-') }.join(' --')}" if both.size > 1
end Try / catch
begin
opts = parser.parse(argv)
rescue Puppet::Util::CommandLine::Trollop::CommandlineError => e
raise unless e.message.include?(' conflicts with --')
loser = e.message[/^--(.+?) conflicts/, 1]
warn "#{e.message} - dropping --#{loser} and keeping the explicit choice"
opts = parser.parse(argv.reject { |t| t == "--#{loser}" })
end Prevention
- 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
When it happens
Trigger: 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.
Common situations: Mutually exclusive output formats or execution modes (verbose/quiet, dry-run/apply); users chaining flags taken from different examples or recipes.
Related errors
- unknown option '%{sym}'
- --%{value0} requires --%{value1}
- unsupported argument type '%{value0}'
- :type specification and default type don't match (default ty
- invalid long option name %{name}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/1478605eb51bd129.
Report an issue: GitHub.