From 9adca58e4fa8e1d94924e64a184532231826496c Mon Sep 17 00:00:00 2001 From: Marco Domingos <66222324+marcoedomingos@users.noreply.github.com> Date: Fri, 27 Sep 2024 08:02:49 +0100 Subject: [PATCH] Fix add package with offline flag (#4395) --- lib/src/command/add.dart | 2 ++ test/add/common/add_test.dart | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index 8282d2c40..5e098b213 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart @@ -88,6 +88,8 @@ For example: @override String get docUrl => 'https://dart.dev/tools/pub/cmd/pub-add'; + @override + bool get isOffline => argResults.flag('offline'); AddCommand() { argParser.addFlag( diff --git a/test/add/common/add_test.dart b/test/add/common/add_test.dart index 6cd2ccba2..645877bba 100644 --- a/test/add/common/add_test.dart +++ b/test/add/common/add_test.dart @@ -1148,4 +1148,14 @@ dependency_overrides: await pubAdd(args: ['foo'], output: contains('+ foo 1.0.0')); }); + + test('`--offline` works', () async { + final server = await servePackages(); + server.serve('foo', '1.0.0'); + await runPub(args: ['cache', 'add', 'foo', '--version', '1.0.0']); + + await d.appDir().create(); + server.serve('foo', '2.0.0'); + await pubAdd(args: ['foo', '--offline']); + }); }