run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
final rest = argResults!.rest;
if (rest.isEmpty) {
Logger.error('Feature name is required.');
Logger.plain('');
Logger.plain('Usage: $invocation');
Logger.plain('Example: srik add feature profile');
return 64;
}
final featureName = rest.first;
final featureError = Validators.featureName(featureName);
if (featureError != null) {
Logger.error(featureError);
return 64;
}
final ctx = ProjectContext.load(Directory.current.path);
if (ctx == null) {
Logger.error(
'No srik.yaml found. Run this command inside a project '
'created with `srik create`.',
);
return 1;
}
try {
FeatureGenerator().generateFeature(ctx, featureName);
return 0;
} on StateError catch (e) {
Logger.error(e.message);
return 1;
} catch (e) {
Logger.error('Failed to generate feature: $e');
return 1;
}
}