execute method
Executes the command with the provided arguments.
Returns an integer exit code (0 for success).
Implementation
@override
Future<int> execute(List<String> arguments) async {
final ArgResults results;
try {
results = _argParser.parse(arguments);
} on FormatException catch (e) {
throw ValidationException(
'Error: ${e.message}\n\nUsage:\n flutter_setup $name <name> --feature <feature_name> [--path <path>]',
);
}
if (results.rest.isEmpty) {
throw ValidationException(
'Error: $_componentType name is required.\n\nUsage:\n flutter_setup $name <name> --feature <feature_name> [--path <path>]',
);
}
final rawComponentName = results.rest.first;
final featureName = results['feature'] as String?;
if (featureName == null || featureName.trim().isEmpty) {
throw ValidationException(
'Error: Option --feature is required.\n\nUsage:\n flutter_setup $name $rawComponentName --feature <feature_name>',
);
}
final targetPath = results['path'] as String? ?? '.';
final vars = VariableResolver.resolveComponent(
rawFeatureName: featureName,
componentType: _componentType,
rawComponentName: rawComponentName,
);
final renderResult = await _generator.generateComponent(
rawFeatureName: featureName,
componentType: _componentType,
rawComponentName: rawComponentName,
projectPath: targetPath,
);
final compPascal =
vars['${_componentType.toLowerCase()}_name_pascal_case']!;
_output.success(
'Generated $_componentType "$compPascal" for feature "$featureName"');
for (final file in renderResult.createdFiles) {
_output.info(' - $file');
}
if (_componentType == 'screen') {
_output.info(
'\nDon\'t forget to add a route for ${compPascal}Screen in lib/app/router/app_router.dart',
);
}
return 0;
}