apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.3k stars 311 forks source link

Add AsyncParsableArguments to support validating async arguments #630

Open luispadron opened 4 months ago

luispadron commented 4 months ago

Currently to share arguments across commands you can create a ParsableArguments type which contains your arguments/options, and can use func validate() throws to validate the arguments.

This fails for things that must be validated in an async manner. We should consider adding an async API for validating or AsyncParsableArguments to support this.

CrazyFanFan commented 4 months ago

I just encountered the same problem.

dcantah commented 4 months ago

Also just hit this.. thought I might've been holding it wrong. I can try and take a look

natecook1000 commented 3 months ago

Given the headaches and challenges around supporting the sync and async versions of run(), I'm reticent to provide another overload here. As a workaround, you can perform any async validation at the start of your async run() method – if you throw a ValidationError from there you'll get the same output as an error thrown from the validate() method.

If this workaround doesn't work for you, please let me know!

luispadron commented 3 months ago

Yeah that works and it's what we do today but it lacks a few things: