run method

  1. @override
FutureOr<int?> run([
  1. DevToolExecutionContext? context
])
override

Runs this tool and returns (either synchronously or asynchronously) an int which will be treated as the exit code (i.e. non-zero means failure).

context is optional. If calling this directly from a dart script, you will most likely want to omit this. DevTools that are converted to a DevToolCommand via toCommand for use in a command-line application will provide a fully-populated DevToolExecutionContext here.

This is the one API member that subclasses need to implement.

Implementation

@override
FutureOr<int?> run([DevToolExecutionContext? context]) async {
  context ??= DevToolExecutionContext();
  if (formatter == Formatter.dartfmt && !dartVersionHasDartfmt) {
    formatter = Formatter.dartFormat;
  }
  final formatExecution = buildExecution(
    context,
    configuredFormatterArgs: formatterArgs,
    defaultMode: defaultMode,
    exclude: exclude,
    formatter: formatter,
    organizeDirectives: organizeDirectives,
  );
  if (formatExecution.exitCode != null) {
    return formatExecution.exitCode;
  }
  var exitCode = await runProcessAndEnsureExit(
    formatExecution.formatProcess!,
    log: _log,
  );
  if (exitCode != 0) {
    return exitCode;
  }
  final directiveOrganization = formatExecution.directiveOrganization;
  if (directiveOrganization != null) {
    exitCode = organizeDirectivesInPaths(
      directiveOrganization.inputs,
      check: directiveOrganization.check,
      verbose: context.verbose,
    );
  }
  return exitCode;
}