From bbb653d64ed0c3b51d1074760dff0f8ff2349d43 Mon Sep 17 00:00:00 2001 From: Renan Araujo Date: Fri, 6 Jan 2023 17:17:40 +0000 Subject: [PATCH] try again --- .../commands/create/create_subcommand.dart | 21 +++++- .../commands/create/commands/legacy_test.dart | 2 +- test/src/commands/create/create_test.dart | 67 +++++++++---------- 3 files changed, 51 insertions(+), 39 deletions(-) diff --git a/lib/src/commands/create/create_subcommand.dart b/lib/src/commands/create/create_subcommand.dart index af6ea3f26..d0865a52d 100644 --- a/lib/src/commands/create/create_subcommand.dart +++ b/lib/src/commands/create/create_subcommand.dart @@ -35,7 +35,7 @@ typedef MasonGeneratorFromBrick = Future Function(Brick); /// /// By default, adds the following arguments to the [argParser]: /// - 'output-directory': the output directory -/// - 'desc': the description of the project +/// - 'description': the description of the project /// /// Sub classes must implement [name], [description] and [template]. /// @@ -97,6 +97,14 @@ abstract class CreateSubCommand extends Command { aliases: ['org'], ); } + + if (this is Publishable) { + argParser.addFlag( + 'publishable', + negatable: false, + help: 'Whether the generated project is intended to be published.', + ); + } } final Analytics _analytics; @@ -236,6 +244,7 @@ abstract class CreateSubCommand extends Command { 'project_name': projectName, 'description': projectDescription, if (this is OrgName) 'org_name': (this as OrgName).orgName, + if (this is Publishable) 'publishable': (this as Publishable).publishable, }; } } @@ -298,3 +307,13 @@ mixin MultiTemplates on CreateSubCommand { ); } } + +/// Mixin for [CreateSubCommand] subclasses that receives the publishable +/// flag. +/// +/// Takes care of parsing it from [argResults] and pass it +/// to the brick generator. +mixin Publishable on CreateSubCommand { + /// Gets the publishable flag. + bool get publishable => argResults['publishable'] as bool? ?? false; +} diff --git a/test/src/commands/create/commands/legacy_test.dart b/test/src/commands/create/commands/legacy_test.dart index 4d8038e85..9ac2cabd0 100644 --- a/test/src/commands/create/commands/legacy_test.dart +++ b/test/src/commands/create/commands/legacy_test.dart @@ -500,7 +500,7 @@ void main() { )..argResultOverrides = argResults; when(() => argResults.rest).thenReturn(['my_app']); when( - () => argResults['desc'] as String?, + () => argResults['description'] as String?, ).thenReturn('very good description'); when(() => argResults['output-directory'] as String?).thenReturn('.tmp'); when(() => generator.id).thenReturn('generator_id'); diff --git a/test/src/commands/create/create_test.dart b/test/src/commands/create/create_test.dart index f30c54f24..835f69b54 100644 --- a/test/src/commands/create/create_test.dart +++ b/test/src/commands/create/create_test.dart @@ -84,47 +84,40 @@ void main() { test( 'Allows the creation of projects in the legacy syntax with no options', withRunner((commandRunner, logger, pubUpdater, printLogs) async { - final tempDir = Directory.systemTemp.createTempSync(); - addTearDown(() => tempDir.deleteSync(recursive: true)); - await IOOverrides.runZoned( + final processResult = _MockProcessResult(); + final process = _MockProcess(); + when(() => processResult.exitCode).thenReturn(ExitCode.success.code); + when( + () => process.run( + any(), + any(), + runInShell: any(named: 'runInShell'), + workingDirectory: any(named: 'workingDirectory'), + ), + ).thenAnswer((_) async => processResult); + await ProcessOverrides.runZoned( () async { - final processResult = _MockProcessResult(); - final process = _MockProcess(); - when(() => processResult.exitCode) - .thenReturn(ExitCode.success.code); - when( - () => process.run( - any(), - any(), - runInShell: any(named: 'runInShell'), - workingDirectory: any(named: 'workingDirectory'), + final result = await commandRunner.run([ + 'create', + 'legacy_project', + ]); + + expect(result, equals(ExitCode.success.code)); + + verify( + () => logger.warn( + 'Deprecated usage of the create command: run ' + "'very_good create --help' to see the available options.", ), - ).thenAnswer((_) async => processResult); - - await ProcessOverrides.runZoned( - () async { - final result = await commandRunner.run([ - 'create', - 'legacy_project', - ]); - - expect(result, equals(ExitCode.success.code)); - - verify( - () => logger.warn( - 'Deprecated usage of the create command: run ' - "'very_good create --help' to see the available options.", - ), - ).called(1); - verify( - () => logger.info('Created a Very Good App! 🦄'), - ).called(1); - }, - runProcess: process.run, - ); + ).called(1); + verify( + () => logger.info('Created a Very Good App! 🦄'), + ).called(1); }, - getCurrentDirectory: () => tempDir, + runProcess: process.run, ); + + Directory('legacy_project').deleteSync(recursive: true); }), );