run method

Future<void> run(
  1. List<String> arguments
)

Executes a command based on the provided arguments.

Supported commands:

  • create: Creates a new Flutter project from a template.
  • icon: Changes the app icon using the flutter_launcher_icons package.
  • help / --help / -h: Displays help information.

Throws:

  • Exception if an unhandled error occurs during command execution.

Implementation

Future<void> run(List<String> arguments) async {
  if (arguments.isEmpty) {
    _printHelp();
    return;
  }

  final command = arguments.first;

  try {
    switch (command) {
      case 'create':
        await CreateCommand(logger).run(arguments.skip(1).toList());
        break;
      case 'icon':
        await IconCommand(logger).run(arguments.skip(1).toList());
        break;
      case 'help':
      case '--help':
      case '-h':
        _printHelp();
        break;
      default:
        logger.err('Unknown command: $command');
        _printHelp();
    }
  } catch (e) {
    logger.err('Error: $e');
    rethrow;
  }
}