Commit b95b67a6 authored by Sebastian Roth's avatar Sebastian Roth Committed by Greg Spencer

allow command line option "--project-name" in flutter create (#22022)

Simple convenience function if users create flutter projects in custom folder structures and but want to specify a custom project name.
parent 4f8acd84
...@@ -95,6 +95,11 @@ class CreateCommand extends FlutterCommand { ...@@ -95,6 +95,11 @@ class CreateCommand extends FlutterCommand {
help: 'The organization responsible for your new Flutter project, in reverse domain name notation. ' help: 'The organization responsible for your new Flutter project, in reverse domain name notation. '
'This string is used in Java package names and as prefix in the iOS bundle identifier.' 'This string is used in Java package names and as prefix in the iOS bundle identifier.'
); );
argParser.addOption(
'project-name',
defaultsTo: null,
help: 'The project name for this new Flutter project. This must be a valid dart package name.'
);
argParser.addOption( argParser.addOption(
'ios-language', 'ios-language',
abbr: 'i', abbr: 'i',
...@@ -235,12 +240,12 @@ class CreateCommand extends FlutterCommand { ...@@ -235,12 +240,12 @@ class CreateCommand extends FlutterCommand {
); );
} }
} }
final String projectName = fs.path.basename(projectDirPath);
String error = _validateProjectDir(projectDirPath, flutterRoot: flutterRoot); String error = _validateProjectDir(projectDirPath, flutterRoot: flutterRoot);
if (error != null) if (error != null)
throwToolExit(error); throwToolExit(error);
final String projectName = argResults['project-name'] ?? fs.path.basename(projectDirPath);
error = _validateProjectName(projectName); error = _validateProjectName(projectName);
if (error != null) if (error != null)
throwToolExit(error); throwToolExit(error);
......
...@@ -298,6 +298,31 @@ void main() { ...@@ -298,6 +298,31 @@ void main() {
); );
}, timeout: allowForCreateFlutterProject); }, timeout: allowForCreateFlutterProject);
testUsingContext('plugin project with valid custom project name', () async {
return _createProject(
projectDir,
<String>['--no-pub', '--template=plugin', '--project-name', 'xyz'],
<String>[
'android/src/main/java/com/example/xyz/XyzPlugin.java',
'example/android/app/src/main/java/com/example/xyzexample/MainActivity.java',
],
unexpectedPaths: <String>[
'android/src/main/java/com/example/flutterproject/FlutterProjectPlugin.java',
'example/android/app/src/main/java/com/example/flutterprojectexample/MainActivity.java',
],
);
}, timeout: allowForCreateFlutterProject);
testUsingContext('plugin project with invalid custom project name', () async {
expect(
() => _createProject(projectDir,
<String>['--no-pub', '--template=plugin', '--project-name', 'xyz.xyz'],
<String>[],
),
throwsToolExit(message: '"xyz.xyz" is not a valid Dart package name.'),
);
}, timeout: allowForCreateFlutterProject);
testUsingContext('legacy app project with-driver-test', () async { testUsingContext('legacy app project with-driver-test', () async {
return _createAndAnalyzeProject( return _createAndAnalyzeProject(
projectDir, projectDir,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment