Skip to content

Commit

Permalink
wip: use paths instead of names with backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wallen committed Jul 9, 2024
1 parent cc786aa commit 89ded61
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions lib/src/commands/create/commands/create_subcommand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,14 @@ abstract class CreateSubCommand extends Command<int> {
return Directory(directory);
}

/// The project name that the user provided.
///
/// Since the project name could be user provided as either:
/// 1. A valid package name
/// 2. '.', the current working directory (the project assumes the cwd's name)
/// this needs to exist to provide a fallback value for [outputDirectory] and
/// [projectName].
String get _projectName {
/// Gets the project name.
String get projectName {
final args = argResults.rest;
_validateProjectName(args);
return args.first;
final name = path.basename(args.first);
_validateProjectName([name]);
return name;
}

/// Gets the project name.
String get projectName => _projectName == '.'
? path.basename(Directory.current.path)
: _projectName;

/// Gets the description for the project.
String get projectDescription => argResults['description'] as String? ?? '';

Expand Down Expand Up @@ -223,12 +213,7 @@ abstract class CreateSubCommand extends Command<int> {

await template.onGenerateComplete(
logger,
Directory(
[
target.dir.path,
if (_projectName != '.') projectName,
].join(Platform.pathSeparator),
),
Directory(path.join(target.dir.path, projectName)),
);

return ExitCode.success.code;
Expand Down

0 comments on commit 89ded61

Please sign in to comment.