execute method

  1. @override
Future<int> execute(
  1. List<String> arguments
)
override

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 ci [init|validate|doctor] [--platform android|ios|all] [--force] [--dry-run]',
    );
  }

  final rest = results.rest;
  final action = rest.isNotEmpty ? rest.first.toLowerCase() : 'init';

  final targetPath = results['path'] as String? ?? '.';
  final dryRun = results['dry-run'] as bool? ?? false;
  final force = results['force'] as bool? ?? false;
  final platformRaw = results['platform'] as String? ?? 'android';

  Validators.validateExistingFlutterProject(Directory(targetPath));

  switch (action) {
    case 'init':
      return await _handleInit(
        projectPath: targetPath,
        platformRaw: platformRaw,
        force: force,
        dryRun: dryRun,
      );

    case 'validate':
    case 'doctor':
      return await _handleDoctor(targetPath);

    default:
      _output.error(
        'Unknown ci action: "$action". Supported actions: init, validate, doctor',
      );
      return 64;
  }
}