run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  // Validate inputs
  if (argResults?.rest.isEmpty ?? true) {
    _handleError('Page name is required');
    return;
  }

  final appsName = (argResults?['apps-name'] as String? ?? '').snakeCase;
  final featureName =
      (argResults?['feature-name'] as String? ?? '').snakeCase;

  // Validate app exists (if specified)
  if (appsName.isNotEmpty) {
    final pathApps = PathHelper.getAppsPath(appsName);
    if (!exists(pathApps)) {
      _handleError('App "$appsName" does not exist');
      return;
    }
  }

  // Validate feature exists
  final pathFeature = PathHelper.getFeaturePath(appsName, featureName);
  if (!exists(pathFeature)) {
    _handleError('Feature "$featureName" does not exist');
    return;
  }

  final pageName = (argResults?.rest.first ?? '').snakeCase;
  final pathPage = PathHelper.getPagePath(appsName, featureName, pageName);

  // Validate page exists
  if (!exists(pathPage)) {
    _handleError('Page "$pageName" does not exist in feature "$featureName"');
    return;
  }

  try {
    // Remove page directory
    _removePageDirectory(appsName, featureName, pageName);

    // Update locator file
    ConfigHelper.removePageFromLocator(appsName, featureName, pageName);

    // Format code
    await _formatCode(pathFeature);

    StatusHelper.success(
        'Successfully removed page "$pageName" from feature "$featureName"');
  } catch (e) {
    _handleError('Failed to remove page "$pageName": ${e.toString()}');
  }
}