Skip to content

Commit bd89adf

Browse files
authored
feat: Add --ignore-warnings flag to pub publish --dry-run (#4698)
1 parent 8a6c067 commit bd89adf

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

lib/src/command/lish.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class LishCommand extends PubCommand {
124124
help: 'Run this in the directory <dir>.',
125125
valueHelp: 'dir',
126126
);
127+
argParser.addFlag(
128+
'ignore-warnings',
129+
help: 'Do not treat warnings as fatal.',
130+
negatable: false,
131+
);
127132
}
128133

129134
Future<void> _publishUsingClient(
@@ -299,6 +304,10 @@ the \$PUB_HOSTED_URL environment variable.''');
299304
if (_toArchive != null && force) {
300305
usageException('Cannot use both --to-archive and --force.');
301306
}
307+
308+
if (argResults.wasParsed('ignore-warnings') && !dryRun) {
309+
usageException('`--ignore-warnings` can only be used with `--dry-run`.');
310+
}
302311
}
303312

304313
Future<_Publication> _publicationFromEntrypoint() async {
@@ -490,7 +499,8 @@ the \$PUB_HOSTED_URL environment variable.''');
490499
: _publicationFromArchive(_fromArchive));
491500
if (dryRun) {
492501
log.message(publication.warningsCountMessage);
493-
if (publication.warningCount != 0) {
502+
if (publication.warningCount != 0 &&
503+
!argResults.flag('ignore-warnings')) {
494504
overrideExitCode(DATA);
495505
}
496506
return;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub/src/exit_codes.dart' as exit_codes;
6+
import 'package:test/test.dart';
7+
8+
import '../descriptor.dart' as d;
9+
import '../test_pub.dart';
10+
11+
void main() {
12+
test('dry-run with warnings exits with DATA error by default', () async {
13+
(await servePackages()).serve('foo', '1.0.0');
14+
await d
15+
.validPackage(
16+
pubspecExtras: {
17+
'dependencies': {'foo': 'any'},
18+
},
19+
)
20+
.create();
21+
22+
await runPub(
23+
args: ['publish', '--dry-run'],
24+
output: contains('Package has 1 warning.'),
25+
exitCode: exit_codes.DATA,
26+
);
27+
});
28+
29+
test(
30+
'dry-run with --ignore-warnings and warnings exits with SUCCESS',
31+
() async {
32+
(await servePackages()).serve('foo', '1.0.0');
33+
await d
34+
.validPackage(
35+
pubspecExtras: {
36+
'dependencies': {'foo': 'any'},
37+
},
38+
)
39+
.create();
40+
41+
await runPub(
42+
args: ['publish', '--dry-run', '--ignore-warnings'],
43+
output: contains('Package has 1 warning.'),
44+
exitCode: exit_codes.SUCCESS,
45+
);
46+
},
47+
);
48+
49+
test('--ignore-warnings without --dry-run is a usage error', () async {
50+
(await servePackages()).serve('foo', '1.0.0');
51+
await d
52+
.validPackage(
53+
pubspecExtras: {
54+
'dependencies': {'foo': 'any'},
55+
},
56+
)
57+
.create();
58+
59+
await runPub(
60+
args: ['publish', '--ignore-warnings'],
61+
error: contains('`--ignore-warnings` can only be used with `--dry-run`.'),
62+
exitCode: exit_codes.USAGE,
63+
);
64+
});
65+
}

test/testdata/goldens/help_test/pub publish --help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Usage: pub publish [options]
1010
-f, --force Publish without confirmation if there are no errors.
1111
--skip-validation Publish without validation and resolution (this will ignore errors).
1212
-C, --directory=<dir> Run this in the directory <dir>.
13+
--ignore-warnings Do not treat warnings as fatal.
1314

1415
Run "pub help" to see global options.
1516
See https://dart.dev/tools/pub/cmd/pub-lish for detailed documentation.

0 commit comments

Comments
 (0)