args
args copied to clipboard
Statically typed argument parser (possibly with code generator)?
Hi thanks for this helpful library! However, it is quite boilerplate to repeat code like:
class CommandOne extends Command<void> {
...
CommandOne() {
argParser.addOption('firstArgument');
argParser.addOption('secondArgument');
}
@override
Future<void> run() async {
final firstArgument = argResults!['firstArgument'] as String;
final secondArgument = argResults!['secondArgument']!.map((e) => int.parse(e)).toList();
...
}
...
}
Since args package is like the Python argparse package, I am hoping it can be enhanced just like how https://typer.tiangolo.com/ Typer does.
In short, the ideal API may be:
class CommandOneArg {
String firstArgument;
List<int> secondArgument;
}
class CommandOne extends Command<CommandOneArg> {
@override
Future<void> run() async {
// just directly use `argResult` which is of type `CommandOneArg`
}
...
}
Interesting idea; I believe that @kevmoo may at one time have authored something like this.
Something like this could also be layered on top of the existing package:args - args wouldn't have to support it directly.
See here! https://pub.dev/packages/build_cli
@devoncarew @kevmoo Thank you! But seems that it does not have commands support (like what I show in my post) yet...