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:
Sebastian Roth 2018-10-17 23:25:46 +08:00 committed by Greg Spencer
parent 4f8acd8462
commit b95b67a66b
2 changed files with 31 additions and 1 deletions

View File

@ -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 {
); );
} }
} }
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);

View File

@ -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,