runInteractive function

Future<void> runInteractive(
  1. String cmd,
  2. List<String> args
)

Runs a cmd with args in interactive mode.

Uses ProcessStartMode.inheritStdio to allow the user to interact directly with the subprocess (e.g. for login prompts).

Implementation

Future<void> runInteractive(String cmd, List<String> args) async {
  print('šŸ‘‰ Running interactive: $cmd ${args.join(" ")}\n');

  final env = getInjectedEnvironment();

  try {
    final process = await Process.start(
      cmd,
      args,
      runInShell: true,
      environment: env,
      mode: ProcessStartMode.inheritStdio,
    );

    final exitCode = await process.exitCode;

    if (exitCode != 0) {
      throw Exception('$cmd failed with exit code $exitCode');
    }

    print('\nāœ… $cmd completed\n');
  } catch (e) {
    print('\nāŒ Error while running interactive $cmd');
    rethrow;
  }
}