{"record":{"id":"264ce14ce2fefab9","repo":"apple/pkl","slug":"commandargumentsmultiplerepeated","errorCode":"commandArgumentsMultipleRepeated","errorMessage":"commandArgumentsMultipleRepeated","messagePattern":"commandArgumentsMultipleRepeated","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/CommandSpecParser.java","lineNumber":230,"sourceCode":"            argAnnotation = annotation;\n          }\n        }\n\n        if (flagAnnotation != null && argAnnotation != null) {\n          throw exceptionBuilder()\n              .withSourceSection(prop.getHeaderSection())\n              .evalError(\"commandOptionBothFlagAndArgument\", prop.getName())\n              .build();\n        }\n\n        if (argAnnotation != null) {\n          var arg = collectArgument(prop, argAnnotation);\n          opts.put(arg.name(), arg);\n          if (arg.repeated()) {\n            if (lastRepeatedArg == null) {\n              lastRepeatedArg = arg;\n            } else {\n              throw exceptionBuilder()\n                  .withSourceSection(optionsClass.getHeaderSection())\n                  .evalError(\"commandArgumentsMultipleRepeated\", lastRepeatedArg.name(), arg.name())\n                  .build();\n            }\n          }\n        } else {\n          CommandSpec.Option flag;\n          if (flagAnnotation == null\n              || flagAnnotation.getVmClass() == CommandModule.getFlagClass()) {\n            flag = collectFlag(prop, flagAnnotation);\n          } else if (flagAnnotation.getVmClass() == CommandModule.getBooleanFlagClass()) {\n            flag = collectBooleanFlag(prop, flagAnnotation);\n          } else if (flagAnnotation.getVmClass() == CommandModule.getCountedFlagClass()) {\n            flag = collectCountedFlag(prop, flagAnnotation);\n          } else {\n            throw PklBugException.unreachableCode();\n          }\n          opts.put(flag.name(), flag);","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/CommandSpecParser.java#L212-L248","documentation":"collectOptions throws commandArgumentsMultipleRepeated when more than one positional @Argument property in the same options class is declared repeated (a list/vararg). At most one trailing repeated argument is allowed, since multiple variadic positionals make parsing ambiguous.","triggerScenarios":"Two or more @Argument properties whose collected spec has repeated() == true (e.g. typed as List/`*type`) within one options class.","commonSituations":"Wanting 'files...' plus 'extraFiles...' variadic positionals in one command; converting several optional arguments to lists without realizing only one variadic is permitted.","solutions":["Keep only one repeated argument and remove/change the others to fixed positionals","Merge the values into a single repeated argument and disambiguate at runtime","Move the second variadic into a subcommand or a named option"],"exampleFix":"// before\n@Argument files: List<String>\n@Argument extra: List<String>\n// after\n@Argument files: List<String>\n@Argument extra: String","handlingStrategy":"validation","validationCode":"const repeatedArgs = argSpecs.filter(a => a.repeated);\nif (repeatedArgs.length > 1) throw new Error(`only one repeated argument allowed: ${repeatedArgs.map(a => a.name)}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Design commands with at most one trailing variadic positional","Make extra positionals required single values","Split complex CLIs into subcommands instead of many variadic args"],"tags":["pkl","cli","command-spec","arguments"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}