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 {
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.'
);
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(
'ios-language',
abbr: 'i',
......@@ -235,12 +240,12 @@ class CreateCommand extends FlutterCommand {
);
}
}
final String projectName = fs.path.basename(projectDirPath);
String error = _validateProjectDir(projectDirPath, flutterRoot: flutterRoot);
if (error != null)
throwToolExit(error);
final String projectName = argResults['project-name'] ?? fs.path.basename(projectDirPath);
error = _validateProjectName(projectName);
if (error != null)
throwToolExit(error);
......
......@@ -298,6 +298,31 @@ void main() {
);
}, 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 {
return _createAndAnalyzeProject(
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