Repository: VeryGoodOpenSource/very_good_cli (dart)

Issue:
feat(create)! subcommand: Very Good Flame Game Usage
Split the create command to use this subcommand: 

```sh
# Very Good Flame Game Usage
very_good create flame_game <project-name> <options>

options:
    --org-name
    --description
```

Pull request description:
## Description

Closes #589

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [x] ✨ New feature (non-breaking change which adds functionality)
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
- [ ] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore

Patch:
diff --git a/.github/workflows/very_good_cli.yaml b/.github/workflows/very_good_cli.yaml
index c616ae177..80cc69abc 100644
--- a/.github/workflows/very_good_cli.yaml
+++ b/.github/workflows/very_good_cli.yaml
@@ -55,10 +55,11 @@ jobs:
           - test/src/commands/test/e2e
           # E2E tests for the create command
           - test/src/commands/create/e2e/flutter_app/core_test.dart
-          - test/src/commands/create/e2e/dart_package/dart_pkg_test.dart
-          - test/src/commands/create/e2e/flutter_package/flutter_pkg_test.dart
           - test/src/commands/create/e2e/dart_cli/dart_cli_test.dart
+          - test/src/commands/create/e2e/dart_package/dart_pkg_test.dart
           - test/src/commands/create/e2e/docs_site/docs_site_test.dart
+          - test/src/commands/create/e2e/flame_game/flame_game_test.dart
+          - test/src/commands/create/e2e/flutter_package/flutter_pkg_test.dart
 
           # E2E tests for the legacy create command syntax
           - test/src/commands/create/e2e/legacy/core_test.dart
diff --git a/lib/src/commands/create/commands/commands.dart b/lib/src/commands/create/commands/commands.dart
index b391a421e..544555cd6 100644
--- a/lib/src/commands/create/commands/commands.dart
+++ b/lib/src/commands/create/commands/commands.dart
@@ -2,6 +2,7 @@ export 'create_subcommand.dart';
 export 'dart_cli.dart';
 export 'dart_package.dart';
 export 'docs_site.dart';
+export 'flame_game.dart';
 export 'flutter_app.dart';
 export 'flutter_package.dart';
 export 'flutter_plugin.dart';
diff --git a/lib/src/commands/create/commands/flame_game.dart b/lib/src/commands/create/commands/flame_game.dart
new file mode 100644
index 000000000..dd19d4a56
--- /dev/null
+++ b/lib/src/commands/create/commands/flame_game.dart
@@ -0,0 +1,32 @@
+import 'package:mason/mason.dart';
+import 'package:usage/usage.dart';
+import 'package:very_good_cli/src/commands/create/commands/create_subcommand.dart';
+import 'package:very_good_cli/src/commands/create/templates/templates.dart';
+
+/// {@template very_good_create_flame_game_command}
+/// A [CreateSubCommand] for creating Flame games.
+/// {@endtemplate}
+class CreateFlameGame extends CreateSubCommand with OrgName {
+  /// {@macro very_good_create_flame_game_command}
+  CreateFlameGame({
+    required Analytics analytics,
+    required Logger logger,
+    required MasonGeneratorFromBundle? generatorFromBundle,
+    required MasonGeneratorFromBrick? generatorFromBrick,
+  }) : super(
+          analytics: analytics,
+          logger: logger,
+          generatorFromBundle: generatorFromBundle,
+          generatorFromBrick: generatorFromBrick,
+        );
+
+  @override
+  String get name => 'flame_game';
+
+  @override
+  String get description =>
+      'Creates a new very good Flame game in the specified directory.';
+
+  @override
+  Template get template => VeryGoodFlameGameTemplate();
+}
diff --git a/lib/src/commands/create/create.dart b/lib/src/commands/create/create.dart
index 689cf447a..ee396c345 100644
--- a/lib/src/commands/create/create.dart
+++ b/lib/src/commands/create/create.dart
@@ -88,6 +88,16 @@ class CreateCommand extends Command<int> {
         generatorFromBrick: generatorFromBrick,
       ),
     );
+
+    // very_good create flame_game <args>
+    addSubcommand(
+      CreateFlameGame(
+        analytics: analytics,
+        logger: logger,
+        generatorFromBundle: generatorFromBundle,
+        generatorFromBrick: generatorFromBrick,
+      ),
+    );
   }
 
   @override


Test patch:
diff --git a/test/src/commands/create/commands/flame_game_test.dart b/test/src/commands/create/commands/flame_game_test.dart
new file mode 100644
index 000000000..3c0775344
--- /dev/null
+++ b/test/src/commands/create/commands/flame_game_test.dart
@@ -0,0 +1,228 @@
+import 'dart:io';
+
+import 'package:args/args.dart';
+import 'package:mason/mason.dart';
+import 'package:mocktail/mocktail.dart';
+import 'package:path/path.dart' as path;
+import 'package:test/test.dart';
+import 'package:usage/usage.dart';
+import 'package:very_good_cli/src/commands/commands.dart';
+import 'package:very_good_cli/src/commands/create/commands/flame_game.dart';
+
+import '../../../../helpers/helpers.dart';
+
+class MockAnalytics extends Mock implements Analytics {}
+
+class MockLogger extends Mock implements Logger {}
+
+class MockMasonGenerator extends Mock implements MasonGenerator {}
+
+class MockGeneratorHooks extends Mock implements GeneratorHooks {}
+
+class MockArgResults extends Mock implements ArgResults {}
+
+class FakeLogger extends Fake implements Logger {}
+
+class FakeDirectoryGeneratorTarget extends Fake
+    implements DirectoryGeneratorTarget {}
+
+final expectedUsage = [
+  '''
+Creates a new very good Flame game in the specified directory.
+
+Usage: very_good create flame_game <project-name> [arguments]
+-h, --help                Print this usage information.
+-o, --output-directory    The desired output directory when creating a new project.
+    --description         The description for this new project.
+                          (defaults to "A Very Good Project created by Very Good CLI.")
+    --org-name            The organization for this new project.
+                          (defaults to "com.example.verygoodcore")
+
+Run "very_good help" to see global options.''',
+];
+
+const pubspec = '''
+name: example
+environment:
+  sdk: ">=2.13.0 <3.0.0"
+''';
+
+void main() {
+  late List<String> progressLogs;
+  late Analytics analytics;
+  late Logger logger;
+
+  setUpAll(() {
+    registerFallbackValue(FakeDirectoryGeneratorTarget());
+    registerFallbackValue(FakeLogger());
+  });
+
+  setUp(() {
+    progressLogs = <String>[];
+
+    analytics = MockAnalytics();
+    when(
+      () => analytics.sendEvent(any(), any(), label: any(named: 'label')),
+    ).thenAnswer((_) async {});
+    when(
+      () => analytics.waitForLastPing(timeout: any(named: 'timeout')),
+    ).thenAnswer((_) async {});
+
+    logger = MockLogger();
+
+    final progress = MockProgress();
+    when(() => progress.complete(any())).thenAnswer((_) {
+      final message = _.positionalArguments.elementAt(0) as String?;
+      if (message != null) progressLogs.add(message);
+    });
+    when(() => logger.progress(any())).thenReturn(progress);
+  });
+
+  group('can be instantiated', () {
+    test('with default options', () {
+      final logger = Logger();
+      final command = CreateFlameGame(
+        analytics: analytics,
+        logger: logger,
+        generatorFromBundle: null,
+        generatorFromBrick: null,
+      );
+      expect(command.name, equals('flame_game'));
+      expect(
+        command.description,
+        equals(
+          'Creates a new very good Flame game in the specified directory.',
+        ),
+      );
+      expect(command.logger, equals(logger));
+    });
+  });
+
+  group('create flame_game', () {
+    test(
+      'help',
+      withRunner((commandRunner, logger, pubUpdater, printLogs) async {
+        final result =
+            await commandRunner.run(['create', 'flame_game', '--help']);
+        expect(printLogs, equals(expectedUsage));
+        expect(result, equals(ExitCode.success.code));
+
+        printLogs.clear();
+
+        final resultAbbr =
+            await commandRunner.run(['create', 'flame_game', '-h']);
+        expect(printLogs, equals(expectedUsage));
+        expect(resultAbbr, equals(ExitCode.success.code));
+      }),
+    );
+
+    group('running the command', () {
+      final generatedFiles =
+          List.filled(10, const GeneratedFile.created(path: ''));
+
+      late GeneratorHooks hooks;
+      late MasonGenerator generator;
+
+      setUp(() {
+        hooks = MockGeneratorHooks();
+        generator = MockMasonGenerator();
+
+        when(() => generator.hooks).thenReturn(hooks);
+        when(
+          () => hooks.preGen(
+            vars: any(named: 'vars'),
+            onVarsChanged: any(named: 'onVarsChanged'),
+          ),
+        ).thenAnswer((_) async {});
+
+        when(
+          () => generator.generate(
+            any(),
+            vars: any(named: 'vars'),
+            logger: any(named: 'logger'),
+          ),
+        ).thenAnswer((_) async {
+          return generatedFiles;
+        });
+
+        when(() => generator.id).thenReturn('generator_id');
+        when(() => generator.description).thenReturn('generator description');
+        when(() => generator.hooks).thenReturn(hooks);
+
+        when(
+          () => hooks.preGen(
+            vars: any(named: 'vars'),
+            onVarsChanged: any(named: 'onVarsChanged'),
+          ),
+        ).thenAnswer((_) async {});
+        when(
+          () => generator.generate(
+            any(),
+            vars: any(named: 'vars'),
+            logger: any(named: 'logger'),
+          ),
+        ).thenAnswer((_) async {
+          final target =
+              _.positionalArguments.first as DirectoryGeneratorTarget;
+          File(path.join(target.dir.path, 'my_app', 'pubspec.yaml'))
+            ..createSync(recursive: true)
+            ..writeAsStringSync(pubspec);
+          return generatedFiles;
+        });
+      });
+
+      test('create flame game', () async {
+        final tempDir = Directory.systemTemp.createTempSync();
+        addTearDown(() => tempDir.deleteSync(recursive: true));
+        final argResults = MockArgResults();
+        final command = CreateFlameGame(
+          analytics: analytics,
+          logger: logger,
+          generatorFromBundle: (_) async => throw Exception('oops'),
+          generatorFromBrick: (_) async => generator,
+        )..argResultOverrides = argResults;
+        when(() => argResults['output-directory'] as String?)
+            .thenReturn(tempDir.path);
+        when(() => argResults.rest).thenReturn(['my_app']);
+        when(() => argResults['application-id'] as String?).thenReturn(
+          'xyz.app.my_app',
+        );
+
+        final result = await command.run();
+
+        expect(command.template.name, 'flame_game');
+        expect(result, equals(ExitCode.success.code));
+
+        verify(() => logger.progress('Bootstrapping')).called(1);
+        verify(
+          () => hooks.preGen(
+            vars: <String, dynamic>{
+              'project_name': 'my_app',
+              'description': '',
+              'org_name': 'com.example.verygoodcore',
+            },
+            onVarsChanged: any(named: 'onVarsChanged'),
+          ),
+        );
+        verify(
+          () => generator.generate(
+            any(),
+            vars: <String, dynamic>{
+              'project_name': 'my_app',
+              'description': '',
+              'org_name': 'com.example.verygoodcore',
+            },
+            logger: logger,
+          ),
+        ).called(1);
+        expect(
+          progressLogs,
+          equals(['Generated ${generatedFiles.length} file(s)']),
+        );
+        verify(
+          () => logger.info('Created a Very Good Game powered by Flame! 🔥🦄'),
+        ).called(1);
+      });
+    });
+  });
+}
diff --git a/test/src/commands/create/commands/legacy_test.dart b/test/src/commands/create/commands/legacy_test.dart
index cf25f086a..5230954b2 100644
--- a/test/src/commands/create/commands/legacy_test.dart
+++ b/test/src/commands/create/commands/legacy_test.dart
@@ -26,6 +26,7 @@ Available subcommands:
   dart_cli          Creates a new very good Dart CLI in the specified directory.
   dart_package      Creates a new very good Dart package in the specified directory.
   docs_site         Creates a new very good docs site in the specified directory.
+  flame_game        Creates a new very good Flame game in the specified directory.
   flutter_app       Creates a new very good Flutter app in the specified directory.
   flutter_package   Creates a new very good Flutter package in the specified directory.
   flutter_plugin    Creates a new very good federated Flutter plugin in the specified directory.
diff --git a/test/src/commands/create/create_test.dart b/test/src/commands/create/create_test.dart
index 2fa248707..8d09b12cb 100644
--- a/test/src/commands/create/create_test.dart
+++ b/test/src/commands/create/create_test.dart
@@ -32,6 +32,7 @@ Available subcommands:
   dart_cli          Creates a new very good Dart CLI in the specified directory.
   dart_package      Creates a new very good Dart package in the specified directory.
   docs_site         Creates a new very good docs site in the specified directory.
+  flame_game        Creates a new very good Flame game in the specified directory.
   flutter_app       Creates a new very good Flutter app in the specified directory.
   flutter_package   Creates a new very good Flutter package in the specified directory.
   flutter_plugin    Creates a new very good federated Flutter plugin in the specified directory.
diff --git a/test/src/commands/create/e2e/flame_game/flame_game_test.dart b/test/src/commands/create/e2e/flame_game/flame_game_test.dart
new file mode 100644
index 000000000..1b6c4c013
--- /dev/null
+++ b/test/src/commands/create/e2e/flame_game/flame_game_test.dart
@@ -0,0 +1,67 @@
+@Tags(['e2e'])
+import 'package:mason/mason.dart';
+import 'package:path/path.dart' as path;
+import 'package:test/test.dart';
+import 'package:universal_io/io.dart';
+
+import '../../../../../helpers/helpers.dart';
+
+void main() {
+  test(
+    'create flame_game',
+    withRunner((commandRunner, logger, updater, logs) async {
+      final directory = Directory.systemTemp.createTempSync();
+
+      final result = await commandRunner.run(
+        [
+          'create',
+          'flame_game',
+          'very_good_flame_game',
+          '-o',
+          directory.path,
+        ],
+      );
+      expect(result, equals(ExitCode.success.code));
+
+      final formatResult = await Process.run(
+        'flutter',
+        ['format', '--set-exit-if-changed', '.'],
+        workingDirectory: path.join(directory.path, 'very_good_flame_game'),
+        runInShell: true,
+      );
+      expect(formatResult.exitCode, equals(ExitCode.success.code));
+      expect(formatResult.stderr, isEmpty);
+
+      final analyzeResult = await Process.run(
+        'flutter',
+        ['analyze', '.'],
+        workingDirectory: path.join(directory.path, 'very_good_flame_game'),
+        runInShell: true,
+      );
+      expect(analyzeResult.exitCode, equals(ExitCode.success.code));
+      expect(analyzeResult.stderr, isEmpty);
+      expect(analyzeResult.stdout, contains('No issues found!'));
+
+      final testResult = await Process.run(
+        'flutter',
+        ['test', '--no-pub', '--coverage'],
+        workingDirectory: path.join(directory.path, 'very_good_flame_game'),
+        runInShell: true,
+      );
+      expect(testResult.exitCode, equals(ExitCode.success.code));
+      expect(testResult.stderr, isEmpty);
+      expect(testResult.stdout, contains('All tests passed!'));
+
+      final testCoverageResult = await Process.run(
+        'genhtml',
+        ['coverage/lcov.info', '-o', 'coverage'],
+        workingDirectory: path.join(directory.path, 'very_good_flame_game'),
+        runInShell: true,
+      );
+      expect(testCoverageResult.exitCode, equals(ExitCode.success.code));
+      expect(testCoverageResult.stderr, isEmpty);
+      expect(testCoverageResult.stdout, contains('lines......: 97.8%'));
+    }),
+    timeout: const Timeout(Duration(minutes: 2)),
+  );
+}