mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
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.
This commit is contained in:
parent
4f8acd8462
commit
b95b67a66b
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user