run method
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('Feature name is required');
return;
}
final appsName = (argResults?['apps-name'] as String? ?? '').snakeCase;
final featureName = (argResults?.rest.first ?? '').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;
}
try {
// Remove feature directory
_removeFeatureDirectory(pathFeature);
// Update locator file
ConfigHelper.removeFeatureFromLocator(appsName, featureName);
// Update pubspec.yaml
ConfigHelper.removeFeatureFromPubspec(appsName, featureName);
// Format code
await _formatCode(appsName);
StatusHelper.success('Successfully removed feature "$featureName"');
} catch (e) {
_handleError('Failed to remove feature "$featureName": ${e.toString()}');
}
}