Unverified Commit 6b8ceb94 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Make the create command call pub get online instead of offline. (#13505)

We thought it would be OK to call the create command offline-only, but it turns out that isn't a great idea because not all of the create template dependencies are cached by running flutter_tool.

This PR makes it go online by default when running pub get after creating a project, and adds an "--offline" flag to the create command so that offline users can use it offline if their cache is warm.
parent 9a957e41
...@@ -32,6 +32,12 @@ class CreateCommand extends FlutterCommand { ...@@ -32,6 +32,12 @@ class CreateCommand extends FlutterCommand {
defaultsTo: true, defaultsTo: true,
help: 'Whether to run "flutter packages get" after the project has been created.' help: 'Whether to run "flutter packages get" after the project has been created.'
); );
argParser.addFlag('offline',
defaultsTo: false,
help: 'When "flutter packages get" is run by the create command, this indicates '
'whether to run it in offline mode or not. In offline mode, it will need to '
'have all dependencies already available in the pub cache to succeed.'
);
argParser.addFlag( argParser.addFlag(
'with-driver-test', 'with-driver-test',
negatable: true, negatable: true,
...@@ -165,7 +171,7 @@ class CreateCommand extends FlutterCommand { ...@@ -165,7 +171,7 @@ class CreateCommand extends FlutterCommand {
await pubGet( await pubGet(
context: PubContext.createPackage, context: PubContext.createPackage,
directory: dirPath, directory: dirPath,
offline: true, offline: argResults['offline'],
); );
final String relativePath = fs.path.relative(dirPath); final String relativePath = fs.path.relative(dirPath);
...@@ -187,7 +193,7 @@ class CreateCommand extends FlutterCommand { ...@@ -187,7 +193,7 @@ class CreateCommand extends FlutterCommand {
await pubGet( await pubGet(
context: PubContext.createPlugin, context: PubContext.createPlugin,
directory: dirPath, directory: dirPath,
offline: true, offline: argResults['offline'],
); );
if (android_sdk.androidSdk != null) if (android_sdk.androidSdk != null)
...@@ -226,7 +232,7 @@ class CreateCommand extends FlutterCommand { ...@@ -226,7 +232,7 @@ class CreateCommand extends FlutterCommand {
); );
if (argResults['pub']) { if (argResults['pub']) {
await pubGet(context: PubContext.create, directory: appPath, offline: true); await pubGet(context: PubContext.create, directory: appPath, offline: argResults['offline']);
injectPlugins(directory: appPath); injectPlugins(directory: appPath);
} }
......
...@@ -303,13 +303,13 @@ void main() { ...@@ -303,13 +303,13 @@ void main() {
); );
}); });
testUsingContext('invokes pub offline', () async { testUsingContext('invokes pub offline when requested', () async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final CreateCommand command = new CreateCommand(); final CreateCommand command = new CreateCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command); final CommandRunner<Null> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--pub', projectDir.path]); await runner.run(<String>['create', '--pub', '--offline', projectDir.path]);
final List<String> commands = loggingProcessManager.commands; final List<String> commands = loggingProcessManager.commands;
expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub'))); expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub')));
expect(commands, contains('--offline')); expect(commands, contains('--offline'));
...@@ -319,6 +319,23 @@ void main() { ...@@ -319,6 +319,23 @@ void main() {
ProcessManager: () => loggingProcessManager, ProcessManager: () => loggingProcessManager,
}, },
); );
testUsingContext('invokes pub online when offline not requested', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = new CreateCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--pub', projectDir.path]);
final List<String> commands = loggingProcessManager.commands;
expect(commands, contains(matches(r'dart-sdk[\\/]bin[\\/]pub')));
expect(commands, isNot(contains('--offline')));
},
timeout: allowForCreateFlutterProject,
overrides: <Type, Generator>{
ProcessManager: () => loggingProcessManager,
},
);
}); });
} }
......
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