run method

void run(
  1. String usecaseName,
  2. String featureName
)

Runs the command to generate a usecase with usecaseName for featureName.

Implementation

void run(String usecaseName, String featureName) {
  if (!Utils.isInitialized()) {
    print('⚠️ Project not initialized. Initializing with core layers...');
    GenerateInitCommand().run();
  }

  final nameSnake = Utils.snake(usecaseName);
  final namePascal = Utils.pascal(usecaseName);
  final featureSnake = Utils.snake(featureName);
  final featurePascal = Utils.pascal(featureName);

  final basePath = 'lib/features/$featureSnake';
  final usecasePath = '$basePath/domain/usecases/${nameSnake}_usecase.dart';
  final diPath = '$basePath/di/${featureSnake}_di.dart';

  Utils.addDependencies();

  if (!Directory(basePath).existsSync()) {
    print('Feature "$featurePascal" does not exist');
    return;
  }

  // Create usecase file
  Utils.createFile(
    usecasePath,
    UsecaseTemplate.usecaseTemplate(nameSnake, featureSnake),
  );

  // Update DI file
  Utils.updateDi(diPath, nameSnake, featureSnake);

  print(
    'Usecase "$namePascal" generated and registered in "$featurePascal" feature',
  );
}