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 {
if (argResults!.rest.isEmpty) {
Logger.error('Missing feature name.');
Logger.info('Usage: karna feature <feature_name>');
return 64;
}
final featureName = argResults!.rest.first;
final memoryAware = argResults!['memory-aware'] as bool;
if (!isValidSnakeCase(featureName)) {
Logger.error(
'Feature name must be snake_case (lowercase letters, numbers, underscores).',
);
return 64;
}
// Check we're in a Flutter project
if (!File('pubspec.yaml').existsSync()) {
Logger.error(
'Not in a Flutter project. Run this from the project root (where pubspec.yaml is).',
);
return 1;
}
if (Directory('lib/features/$featureName').existsSync()) {
Logger.error("Feature '$featureName' already exists.");
return 1;
}
Logger.info('🚀 Creating feature: $featureName');
Logger.newLine();
await generateFeature(
featureName: featureName,
memoryAware: memoryAware,
);
return 0;
}