Commit 71aaa5db authored by Devon Carew's avatar Devon Carew Committed by GitHub

add --offline to flutter packages get (#8707)

parent f5a6c432
...@@ -40,7 +40,12 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -40,7 +40,12 @@ class PackagesGetCommand extends FlutterCommand {
final bool upgrade; final bool upgrade;
PackagesGetCommand(this.name, this.upgrade); PackagesGetCommand(this.name, this.upgrade) {
argParser.addFlag('offline',
negatable: false,
help: 'Use cached packages instead of accessing the network.'
);
}
// TODO: implement description // TODO: implement description
@override @override
...@@ -68,6 +73,11 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -68,6 +73,11 @@ class PackagesGetCommand extends FlutterCommand {
// TODO: If the user is using a local build, we should use the packages from their build instead of the cache. // TODO: If the user is using a local build, we should use the packages from their build instead of the cache.
await pubGet(directory: target, upgrade: upgrade, checkLastModified: false); await pubGet(
directory: target,
upgrade: upgrade,
offline: argResults['offline'],
checkLastModified: false
);
} }
} }
...@@ -29,6 +29,7 @@ Future<Null> pubGet({ ...@@ -29,6 +29,7 @@ Future<Null> pubGet({
String directory, String directory,
bool skipIfAbsent: false, bool skipIfAbsent: false,
bool upgrade: false, bool upgrade: false,
bool offline: false,
bool checkLastModified: true bool checkLastModified: true
}) async { }) async {
if (directory == null) if (directory == null)
...@@ -47,8 +48,10 @@ Future<Null> pubGet({ ...@@ -47,8 +48,10 @@ Future<Null> pubGet({
final String command = upgrade ? 'upgrade' : 'get'; final String command = upgrade ? 'upgrade' : 'get';
final Status status = logger.startProgress("Running 'flutter packages $command' in ${fs.path.basename(directory)}...", final Status status = logger.startProgress("Running 'flutter packages $command' in ${fs.path.basename(directory)}...",
expectSlowOperation: true); expectSlowOperation: true);
final int code = await runCommandAndStreamOutput( final List<String> args = <String>[sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'];
<String>[sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'], if (offline)
args.add('--offline');
final int code = await runCommandAndStreamOutput(args,
workingDirectory: directory, workingDirectory: directory,
mapFunction: _filterOverrideWarnings, mapFunction: _filterOverrideWarnings,
environment: <String, String>{ 'FLUTTER_ROOT': Cache.flutterRoot } environment: <String, String>{ 'FLUTTER_ROOT': Cache.flutterRoot }
......
...@@ -37,13 +37,18 @@ void main() { ...@@ -37,13 +37,18 @@ void main() {
await runner.run(<String>['create', '--no-pub', temp.path]); await runner.run(<String>['create', '--no-pub', temp.path]);
} }
Future<Null> runCommand(String verb) async { Future<Null> runCommand(String verb, { List<String> args }) async {
await createProject(); await createProject();
final PackagesCommand command = new PackagesCommand(); final PackagesCommand command = new PackagesCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command); final CommandRunner<Null> runner = createTestCommandRunner(command);
await runner.run(<String>['packages', verb, temp.path]); final List<String> commandArgs = <String>['packages', verb];
if (args != null)
commandArgs.addAll(args);
commandArgs.add(temp.path);
await runner.run(commandArgs);
} }
void expectExists(String relPath) { void expectExists(String relPath) {
...@@ -57,6 +62,12 @@ void main() { ...@@ -57,6 +62,12 @@ void main() {
expectExists('.packages'); expectExists('.packages');
}); });
testUsingContext('get --offline', () async {
await runCommand('get', args: <String>['--offline']);
expectExists('lib/main.dart');
expectExists('.packages');
});
testUsingContext('upgrade', () async { testUsingContext('upgrade', () async {
await runCommand('upgrade'); await runCommand('upgrade');
expectExists('lib/main.dart'); expectExists('lib/main.dart');
......
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