runInteractiveCodemodSequence function

Future<int> runInteractiveCodemodSequence(
  1. Iterable<String> filePaths,
  2. Iterable<Suggestor> suggestors, {
  3. Iterable<String> args = const [],
  4. bool defaultYes = false,
  5. String? additionalHelpOutput,
  6. String? changesRequiredOutput,
})

Exactly the same as runInteractiveCodemod except that it runs all of the given suggestors sequentially (meaning that the set of files found by query is iterated over for each suggestor).

This can be useful if a certain modification needs to happen prior to another, or if you need to use a "collector" pattern wherein the first suggestor collects information from the files that a second suggestor will then use to suggest patches.

If your suggestors don't need to be applied in a particular order, consider combining them into a single "aggregate" suggestor and using runInteractiveCodemod instead: final query = ...; runInteractiveCodemod( query, AggregateSuggestor(SuggestorA(), SuggestorB()), );

Implementation

Future<int> runInteractiveCodemodSequence(
  Iterable<String> filePaths,
  Iterable<Suggestor> suggestors, {
  Iterable<String> args = const [],
  bool defaultYes = false,
  String? additionalHelpOutput,
  String? changesRequiredOutput,
}) async {
  try {
    ArgResults parsedArgs;
    try {
      parsedArgs = codemodArgParser.parse(args);
    } on ArgParserException catch (e) {
      stderr
        ..writeln('Invalid codemod arguments: ${e.message}')
        ..writeln()
        ..writeln(codemodArgParser.usage);
      return ExitCode.usage.code;
    }

    if (parsedArgs['help'] == true) {
      stderr.writeln('Global codemod options:');
      stderr.writeln();
      stderr.writeln(codemodArgParser.usage);

      additionalHelpOutput ??= '';
      if (additionalHelpOutput.isNotEmpty) {
        stderr.writeln();
        stderr.writeln('Additional options for this codemod:');
        stderr.writeln(additionalHelpOutput);
      }
      return ExitCode.success.code;
    }
    return overrideAnsiOutput<Future<int>>(
        stdout.supportsAnsiEscapes,
        () => _runInteractiveCodemod(filePaths, suggestors, parsedArgs,
            defaultYes: defaultYes,
            changesRequiredOutput: changesRequiredOutput));
  } catch (error, stackTrace) {
    stderr
      ..writeln('Uncaught exception:')
      ..writeln(error)
      ..writeln(stackTrace);
    return ExitCode.software.code;
  }
}