runSeedRegistryEntrypoint function

Future<void> runSeedRegistryEntrypoint({
  1. required List<String> args,
  2. required List<SeederRegistration> seeds,
  3. void beforeRun(
    1. OrmConnection connection
    )?,
})

Implementation

Future<void> runSeedRegistryEntrypoint({
  required List<String> args,
  required List<SeederRegistration> seeds,
  void Function(OrmConnection connection)? beforeRun,
}) async {
  if (seeds.isEmpty) {
    stdout.writeln(jsonEncode(const []));
    return;
  }

  // Build a small Artisan runner around `run` and `info` commands so we get
  // global flags, better help, and consistent IO.
  final runner =
      CommandRunner<void>(
          'seeds',
          'Seed registry entrypoint',
          ansi: stdout.supportsAnsiEscapes,
        )
        ..addCommand(
          _SeedRegistryRunCommand(seeds: seeds, beforeRun: beforeRun),
        )
        ..addCommand(_SeedRegistryInfoCommand(seeds: seeds));

  // - If --help is passed alone, show top-level help with both commands.
  // - If args are empty or start with other flags (e.g., --pretend), default to `run`.
  // - Otherwise, treat first arg as the subcommand (e.g., `info`).
  final forwarded =
      (args.isEmpty ||
          (args.first.startsWith('-') &&
              args.first != '--help' &&
              args.first != '-h'))
      ? ['run', ...args]
      : args;

  await runner.run(forwarded);
}