swift-argument-parser
swift-argument-parser copied to clipboard
[WIP] Add ArgumentSource as the projected value of arguments
Description
This adds a new ArgumentSource type as the projected value for @Argument, @Option, and @Flag types. This way, you can access the original string and location in the command-line arguments that produced a value.
struct Example: ParsableCommand {
@Argument()
var name: String
@Option()
var age: Int
func run() {
print("Your name is \(name) and your age is \(age).")
if $name.source.first!.position < $age.source.first!.position {
print("You gave your name before your age.")
} else {
print("You gave your age before your name.")
}
}
}
$ example --age 43 Blake
Your name is Blake and your age is 43.
You gave your age before your name.
Detailed Design
TK
Documentation Plan
TK
Test Plan
TK
Source Impact
This would be an additive change only.
Checklist
- [ ] I've added at least one test that validates that my change is working, if appropriate
- [x] I've followed the code style of the rest of the project
- [x] I've read the Contribution Guidelines
- [ ] I've updated the documentation if necessary
Neat idea!
Looks good, @natecook1000! Thanks for adding this.