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 {
  if (args.isNotEmpty) {
    print('Unknown option "${args.first}". Usage: dox $usage');
    exitCode = 1;
    return;
  }
  Installer installer = Installer(root: root, runner: runner);
  String app = installer.appName;

  if (!installer.hasDependency('dox_orm') ||
      !installer.hasDependency('dox_migration')) {
    print('dox_auth needs the ORM. Run `dox add orm` first.');
    exitCode = 1;
    return;
  }
  if (!File('${installer.root.path}/$userModel').existsSync()) {
    print(
      'There is no $userModel. Make the model first: '
      '`dox make:model User -m`. If your User model is elsewhere, write '
      'lib/config/auth.dart by hand (see the authentication docs).',
    );
    exitCode = 1;
    return;
  }

  /// an app with its own config is set up already: change nothing else
  bool hasConfig = File('${installer.root.path}/lib/config/auth.dart')
      .existsSync();

  await installer.addDependency('dox_auth');
  await installer.addDependency('dox_builder', dev: true);
  await installer.addDependency('build_runner', dev: true);

  if (hasConfig) {
    installer.note('skipped  lib/config/auth.dart (already there)');
    installer.note('skipped  provider and tokens migration');
    installer.printSummary(<String>[
      'lib/config/auth.dart is already there, so the provider and the '
          'tokens migration were not added. Add them by hand if you need '
          'them: `dox auth:tokens-table` makes the migration. See the '
          'authentication docs.',
    ]);
    return;
  }
  installer.writeFile('lib/config/auth.dart', authConfig(app));
  installer.writeFile('lib/providers/auth_provider.dart', authProvider(app));
  _addTokensMigration(installer);

  await installer.buildRunner();
  installer.printSummary(<String>[
    'Make the tokens table: `dox migrate`.',
    'Add the login routes and a controller, see the authentication docs: '
        'https://dartondox.dev/latest/security/authentication/',
  ]);
}