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 {
  List<String> options = <String>[];
  Set<String> seen = <String>{};
  bool uuid = false;
  bool stringIds = false;
  String? usersTable;
  String? usersKey;
  for (String arg in args) {
    String flag = arg.split('=').first;
    if (!seen.add(flag)) {
      _fail('$flag is given more than once.');
      return;
    }
    if (arg == '--uuid') {
      uuid = true;
    } else if (arg == '--string-ids') {
      stringIds = true;
    } else if (arg.startsWith('--users-table=')) {
      usersTable = _name(arg, '--users-table=');
      if (usersTable == null) return;
    } else if (arg.startsWith('--users-key=')) {
      usersKey = _name(arg, '--users-key=');
      if (usersKey == null) return;
    } else {
      _fail('Unknown option "$arg". Usage: dox $usage');
      return;
    }
  }
  if (usersTable != null) {
    options.add("usersTable: '$usersTable'");
    if (usersKey != null) options.add("usersKey: '$usersKey'");
  } else if (usersKey != null) {
    print('Warning: --users-key does nothing without --users-table.');
  }
  if (uuid && stringIds) {
    _fail('Use --uuid or --string-ids, not both.');
    return;
  }
  if (uuid) options.insert(0, 'uuidIds: true');
  if (stringIds) options.insert(0, 'stringIds: true');

  String? path = _migrations.create(
    'create_access_tokens_table',
    source(options),
  );
  if (path == null) {
    _fail(
      'A create_access_tokens_table migration is already in db/migration.',
    );
    return;
  }
  String file = File(path).uri.pathSegments.last;
  print('\x1B[32m$file migration created successfully.\x1B[0m');
  if (uuid) print('Set uuidIds: true on AccessTokenAuthDriver too.');
  if (stringIds) print('Set stringIds: true on AccessTokenAuthDriver too.');
  print('Run `dox migrate` to make the table.');
}