Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/test/commands/create/flame_game/flame_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void main() {
['coverage/lcov.info', '-o', 'coverage'],
workingDirectory: workingDirectory,
);
expect(testCoverageResult.stdout, contains('lines......: 97.9%'));
expect(testCoverageResult.stdout, contains('lines......: 97.8%'));
}),
);
}
72 changes: 43 additions & 29 deletions lib/src/commands/create/commands/create_subcommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,53 @@ abstract class CreateSubCommand extends Command<int> {

/// Gets the output [Directory].
Directory get outputDirectory {
final directory = argResults['output-directory'] as String? ?? '.';
return Directory(directory);
final directoryParameter = argResults['output-directory'] as String?;
final args = argResults.rest;

if (args.first == '.' && directoryParameter != null) {
usageException(
'''--output-directory cannot be specified when using "very_good create <template> ."''',
);
}

if (directoryParameter != null) {
return Directory('$directoryParameter/$projectName');
}

return Directory(args.first);
}

/// Gets the project name.
String get projectName {
final args = argResults.rest;
_validateProjectName(args);
return args.first;

if (args.isEmpty) {
usageException('No option specified for the project name.');
}

if (args.length > 1) {
usageException('Multiple project names specified.');
}

final projectName = args.first;
if (projectName.contains('/')) {
usageException('Project name cannot contain "/".');
}

final name = args.first == '.'
? path.basename(Directory.current.path)
: projectName;

final isValidPackageName = _isValidPackageName(name);

if (!isValidPackageName) {
usageException(
'"$name" is not a valid package name.\n\n'
'See https://dart.dev/tools/pub/pubspec#name for more information.',
);
}

return name;
}

/// Gets the description for the project.
Expand All @@ -147,27 +185,6 @@ abstract class CreateSubCommand extends Command<int> {
return match != null && match.end == name.length;
}

void _validateProjectName(List<String> args) {
logger.detail('Validating project name; args: $args');

if (args.isEmpty) {
usageException('No option specified for the project name.');
}

if (args.length > 1) {
usageException('Multiple project names specified.');
}

final name = args.first;
final isValidProjectName = _isValidPackageName(name);
if (!isValidProjectName) {
usageException(
'"$name" is not a valid package name.\n\n'
'See https://dart.dev/tools/pub/pubspec#name for more information.',
);
}
}

Future<MasonGenerator> _getGeneratorForTemplate() async {
try {
final brick = Brick.version(
Expand Down Expand Up @@ -209,10 +226,7 @@ abstract class CreateSubCommand extends Command<int> {
final files = await generator.generate(target, vars: vars, logger: logger);
generateProgress.complete('Generated ${files.length} file(s)');

await template.onGenerateComplete(
logger,
Directory(path.join(target.dir.path, projectName)),
);
await template.onGenerateComplete(logger, outputDirectory);

return ExitCode.success.code;
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/src/commands/create/commands/dart_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_cli', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
2 changes: 1 addition & 1 deletion test/src/commands/create/commands/dart_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_package', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
2 changes: 1 addition & 1 deletion test/src/commands/create/commands/docs_site_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_docs_site', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
2 changes: 1 addition & 1 deletion test/src/commands/create/commands/flame_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_app', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
2 changes: 1 addition & 1 deletion test/src/commands/create/commands/flutter_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_app', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_flutter_package', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void main() {
).thenAnswer((invocation) async {
final target =
invocation.positionalArguments.first as DirectoryGeneratorTarget;
File(path.join(target.dir.path, 'my_plugin', 'pubspec.yaml'))
File(path.join(target.dir.path, 'pubspec.yaml'))
..createSync(recursive: true)
..writeAsStringSync(pubspec);
return generatedFiles;
Expand Down
Loading