run method
Parses args
and invokes Command.run
on the chosen command.
This always returns a Future in case the command is asynchronous. The
Future will throw a UsageException
if args
was invalid.
Implementation
@override
Future<void> run(Iterable<String> args, {Directory? directory}) async {
ArgResults results = args.isEmpty ? parse(['check']) : parse(args);
Ansi? ansi;
if (results.wasParsed('color')) {
ansi = Ansi(results['color']);
}
logger ??= Logger.standard(ansi: ansi);
if (results['version']) {
_out('$appName version $appVersion');
return Future.value();
}
if (results['directory'] != null) {
Directory dir = Directory(results['directory']);
if (!dir.existsSync()) {
String message = 'Directory specified does not exist "${dir.path}".';
_out('Error: $message');
throw UsageException(message, usage);
}
directory = dir;
}
String sdkPath =
results.wasParsed('dart-sdk') ? results['dart-sdk'] : getSdkPath();
directory ??= Directory.current;
if (results['verbose']) {
logger = Logger.verbose(ansi: ansi);
}
project = Project(directory, sdkPath, logger!);
return runCommand(results);
}