unscripted icon indicating copy to clipboard operation
unscripted copied to clipboard

Automatic "allowed" when parameter is an enum

Open seaneagan opened this issue 12 years ago • 2 comments

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

seaneagan avatar Dec 18 '13 16:12 seaneagan

Getting close:

https://chromiumcodereview.appspot.com/938513002/

seaneagan avatar Feb 24 '15 20:02 seaneagan

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.

seaneagan avatar Apr 27 '15 19:04 seaneagan