diff --git a/Sources/ArgumentParser/Parsing/CommandParser.swift b/Sources/ArgumentParser/Parsing/CommandParser.swift index d7642c89b..4ccf02b7e 100644 --- a/Sources/ArgumentParser/Parsing/CommandParser.swift +++ b/Sources/ArgumentParser/Parsing/CommandParser.swift @@ -159,6 +159,7 @@ extension CommandParser { do { try parsedCommand.validate() } catch { + try checkForBuiltInFlags(split) throw CommandError(commandStack: commandStack, parserError: ParserError.userValidationError(error)) } diff --git a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift index 122ddea04..be1e583bc 100644 --- a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift @@ -317,4 +317,27 @@ extension HelpGenerationTests { """) } + struct K: ParsableCommand { + @Argument(help: "A list of paths.") + var paths: [String] + + func validate() throws { + if paths.isEmpty { + throw ValidationError("At least one path must be specified.") + } + } + } + + func testHelpWithNoValueForArray() { + AssertHelp(for: K.self, equals: """ + USAGE: k [ ...] + + ARGUMENTS: + A list of paths. + + OPTIONS: + -h, --help Show help information. + + """) + } }