{"record":{"id":"399d548d4a65c51f","repo":"puppetlabs/puppet","slug":"value0-requires-value1","errorCode":null,"errorMessage":"--%{value0} requires --%{value1}","messagePattern":"--%(.+?) requires --%(.+?)","errorType":"exception","errorClass":"CommandlineError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/command_line/trollop.rb","lineNumber":406,"sourceCode":"        end\n\n        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","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/command_line/trollop.rb#L388-L424","documentation":"Constraints registered with depends(*syms) are evaluated after token parsing (trollop.rb:399-410): if any member of the group was given on the command line, every other member must also appear, else parse raises CommandlineError '--x requires --y' at line 406 with both long names interpolated from @specs. A :default value does not satisfy a depends constraint — only the literal presence of the flag on the command line counts.","triggerScenarios":"`mytool --encrypt` when the tool declared `depends :encrypt, :key` and --key is absent; giving one member of a paired option set such as --bucket without --bucket-server.","commonSituations":"Options designed as pairs (mode + target, output + format); users copying a partial example command line; documentation showing only one of the two required flags.","solutions":["Add the missing partner flag named in the message","Consult --help for dependency notes before running","As the developer, drop the depends constraint and validate in code after parsing so you can emit a clearer, context-aware message"],"exampleFix":"# before (tool declared depends :encrypt, :key)\n$ mytool --encrypt\nError: --encrypt requires --key\n\n# after\n$ mytool --encrypt --key /etc/mytool/key.pem","handlingStrategy":"try-catch","validationCode":"# Check depends groups before parse by asking the parser for its constraints\nconstraints = parser.instance_variable_get(:@constraints)\ngiven = argv.map { |t| t[/^--no-?(.+)/, 1]&.tr('-', '_')&.to_sym }.compact\nconstraints.select { |type, _| type == :depends }.each do |_, syms|\n  next unless (syms & given).any?\n  missing = syms - given\n  abort \"Missing required companion option(s): --#{missing.map { |s| s.to_s.tr('_', '-') }.join(' --')}\" unless missing.empty?\nend","typeGuard":null,"tryCatchPattern":"begin\n  opts = parser.parse(argv)\nrescue Puppet::Util::CommandLine::Trollop::CommandlineError => e\n  raise unless e.message.include?(' requires --')\n  partner = e.message[/requires --(.+)$/, 1]\n  warn \"#{e.message}. Re-running with --#{partner} included.\"\n  retry_with = argv + [\"--#{partner}\"]\n  opts = parser.parse(retry_with)   # only if a sensible default value exists\nend","preventionTips":["Read --help for companion flags before running commands with paired options","Document depends pairs prominently in tool READMEs - users typically copy partial examples","As a developer, prefer post-parse validation with a contextual message over bare depends when requirements are conditional"],"tags":["puppet","trollop","cli","option-parsing","constraints"],"backgroundTag":"missing-dependent-option","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}