-
Notifications
You must be signed in to change notification settings - Fork 352
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
My command accepts a list of paths as arguments, using @Argument() var paths: [String]. I couldn't find a built in way to validate that the array is non-empty, so I implemented validate() and throw a ValidationError in that case. Because CommandParser validates commands before checking if help was requested, only a short usage string is ever displayed, instead of the full help text.
ArgumentParser version: 0.0.6
Swift version:
Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
Target: x86_64-apple-darwin19.4.0
Checklist
- If possible, I've reproduced the issue using the
masterbranch of this package - I've searched for existing GitHub issues
Steps to Reproduce
Paste this into a new Swift package:
import ArgumentParser
struct Test: 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 run() throws {
for path in paths {
print(path)
}
}
}
Test.main()Then run swift run test --help.
Expected behavior
Expected the command to output the help text.
Actual behavior
Received this output instead:
Error: At least one path must be specified.
Usage: test [<paths> . . .]
msewell
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working