Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
renancaraujo committed Jan 6, 2023
1 parent 021950b commit bbb653d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 39 deletions.
21 changes: 20 additions & 1 deletion lib/src/commands/create/create_subcommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef MasonGeneratorFromBrick = Future<MasonGenerator> 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].
///
Expand Down Expand Up @@ -97,6 +97,14 @@ abstract class CreateSubCommand extends Command<int> {
aliases: ['org'],
);
}

if (this is Publishable) {
argParser.addFlag(
'publishable',
negatable: false,
help: 'Whether the generated project is intended to be published.',
);
}
}

final Analytics _analytics;
Expand Down Expand Up @@ -236,6 +244,7 @@ abstract class CreateSubCommand extends Command<int> {
'project_name': projectName,
'description': projectDescription,
if (this is OrgName) 'org_name': (this as OrgName).orgName,
if (this is Publishable) 'publishable': (this as Publishable).publishable,
};
}
}
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion test/src/commands/create/commands/legacy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
67 changes: 30 additions & 37 deletions test/src/commands/create/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
);

Expand Down

0 comments on commit bbb653d

Please sign in to comment.