add --offline to flutter packages get (#8707)
This commit is contained in:
@@ -40,7 +40,12 @@ class PackagesGetCommand extends FlutterCommand {
|
||||
|
||||
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
|
||||
@override
|
||||
@@ -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.
|
||||
|
||||
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({
|
||||
String directory,
|
||||
bool skipIfAbsent: false,
|
||||
bool upgrade: false,
|
||||
bool offline: false,
|
||||
bool checkLastModified: true
|
||||
}) async {
|
||||
if (directory == null)
|
||||
@@ -47,8 +48,10 @@ Future<Null> pubGet({
|
||||
final String command = upgrade ? 'upgrade' : 'get';
|
||||
final Status status = logger.startProgress("Running 'flutter packages $command' in ${fs.path.basename(directory)}...",
|
||||
expectSlowOperation: true);
|
||||
final int code = await runCommandAndStreamOutput(
|
||||
<String>[sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'],
|
||||
final List<String> args = <String>[sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'];
|
||||
if (offline)
|
||||
args.add('--offline');
|
||||
final int code = await runCommandAndStreamOutput(args,
|
||||
workingDirectory: directory,
|
||||
mapFunction: _filterOverrideWarnings,
|
||||
environment: <String, String>{ 'FLUTTER_ROOT': Cache.flutterRoot }
|
||||
|
||||
@@ -37,13 +37,18 @@ void main() {
|
||||
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();
|
||||
|
||||
final PackagesCommand command = new PackagesCommand();
|
||||
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) {
|
||||
@@ -57,6 +62,12 @@ void main() {
|
||||
expectExists('.packages');
|
||||
});
|
||||
|
||||
testUsingContext('get --offline', () async {
|
||||
await runCommand('get', args: <String>['--offline']);
|
||||
expectExists('lib/main.dart');
|
||||
expectExists('.packages');
|
||||
});
|
||||
|
||||
testUsingContext('upgrade', () async {
|
||||
await runCommand('upgrade');
|
||||
expectExists('lib/main.dart');
|
||||
|
||||
Reference in New Issue
Block a user