run method

  1. @override
Future<void> run(
  1. List<String> args
)

run the command. args are the words after the name.

Implementation

@override
Future<void> run(List<String> args) async {
  String? driver = _driver(args);
  if (driver == null) {
    print(
      'Unknown option. Use --driver=database, --driver=redis or '
      '--driver=sync (database when not given).',
    );
    exitCode = 1;
    return;
  }
  Installer installer = Installer(root: root, runner: runner);
  String app = installer.appName;
  driver = _keptDriver(installer, driver);

  await installer.addDependency('dox_core');
  await installer.addDependency('dox_builder', dev: true);
  await installer.addDependency('build_runner', dev: true);
  if (driver == 'database') {
    await installer.addDependency('dox_queue_database');
  }

  installer.writeFile('lib/config/queue.dart', queueConfig(app, driver));
  installer.writeFile(
    'lib/providers/queue_provider.dart',
    queueProvider(app, driver),
  );
  installer.writeFile('bin/queue.dart', queueEntry(app));
  installer.writeFile('lib/app/jobs/send_welcome_email.job.dart', sampleJob);

  if (driver == 'redis') {
    installer.addEnv('REDIS_HOST', '127.0.0.1');
    installer.addEnv('REDIS_PORT', '6379');
  }

  bool needsMigration = driver == 'database' && _addMigration(installer);
  await installer.buildRunner();
  installer.printSummary(<String>[
    if (driver == 'database' && !needsMigration)
      'The database driver needs the jobs tables. Run `dox add orm` '
          'first, then run `dox add queue` again to get the migration.',
    if (needsMigration) 'Make the jobs tables: `dox migrate`.',
    if (driver == 'redis')
      'Start Redis. Check REDIS_HOST and REDIS_PORT in .env.',
    if (driver != 'sync')
      'Run the worker next to the server: `dox queue:work`.',
    'Send a job: `await SendWelcomeEmail(userId: 1).dispatch();`',
  ]);
}