unscripted
unscripted copied to clipboard
Automatic "allowed" when parameter is an enum
When dart supports enums, it should be possible to annotate a parameter as an enum, and have the "allowed" configuration automatically set. May need to provide configuration of how the enum constant names are mapped to strings. The help text could come from the doc comments of the enum constants, as in #11
Getting close:
https://chromiumcodereview.appspot.com/938513002/
Since it's still not possible to access doc-comments using mirrors, it could be:
main(args) => new Script(peel).execute(args);
@Command(help: 'Peel a fruit')
peel(Fruit fruit) {
print('Peeling the ${fruit.name}')
}
enum Fruit {
@Help('Tart.') apple,
@Help('Citrusy.') orange,
@Help('Aromatic.') banana
}
peel -h
peel <fruit>
<fruit>
[apple] Tart.
[orange] Citusy.
[banana] Aromatic.
For enum.name, see http://dartbug.com/21712.