run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
final rest = argResults!.rest;
if (rest.length < 2) {
throw UsageException('Expected: rekeens generate <type> <name>', usage);
}
final type = rest[0];
final force = argResults!['force'] as bool;
final dryRun = argResults!['dry-run'] as bool;
final withTests = argResults!['tests'] as bool;
final hooksEnabled = argResults!['hooks'] as bool;
final addFields = argResults!['add-field'] as List<String>;
final removeFields = argResults!['remove-field'] as List<String>;
if ((addFields.isNotEmpty || removeFields.isNotEmpty) && type != 'model') {
throw UsageException(
'--add-field/--remove-field are only supported for models.',
usage,
);
}
final featureName = rest[1];
final entityName = rest.length > 2 ? rest[2] : null;
final hookSet = hooksEnabled
? ConfigLoader.loadHooks(workingDirectory: _workingDirectory)
: const HookSet();
final context = HookContext(
generatorType: type,
featureName: featureName,
entityName: entityName,
dryRun: dryRun,
);
if (hooksEnabled && hookSet.beforeGenerate.isNotEmpty) {
await _hookRunner.runHooks(hookSet.beforeGenerate, context);
}
await _runGenerator(
type,
rest,
force,
dryRun,
withTests,
addFields,
removeFields,
);
if (hooksEnabled && hookSet.afterGenerate.isNotEmpty) {
await _hookRunner.runHooks(hookSet.afterGenerate, context);
}
}