Trouble writing tasks with TaskArgs params.
- Dominant language
- Dart
- Stars
- 266
- Forks
- 36
- Avg merge
- 23h 25m
- Merged PRs (30d)
- 2
Description
Follow-up from: https://github.com/dart-lang/linter/pull/889.
The rub is that using the documented API, with a task written like this:
```dart
@Task('Generate a lint rule stub.')
rule(TaskArgs args) {
String name = args.getOption('name');
generateRule(name, outDir: Directory.current.path);
}
```
I get an exception at runtime:
```
$ grind rule --name=foo
NoSuchMethodError: Class 'GrinderContext' has no instance method 'getOption'.
Receiver: Instance of 'GrinderContext'
Tried calling: getOption("name")
```
Defining the rule to take a context works though:
```dart
@Task('Generate a lint rule stub.')
rule(GrinderContext context) {
TaskArgs args = context.invocation.arguments;
String name = args.getOption('name');
generateRule(name, outDir: Directory.current.path);
}
```
but I don't think that indirection is intended (and there's a `context` getter besides).
Contributor guide
Assessment
This issue has not been assessed yet.