Fix --verbose doc, and accept verboseness setting from embedder (#3279)
diff --git a/lib/pub.dart b/lib/pub.dart
index 5b3054f..71de9d6 100644
--- a/lib/pub.dart
+++ b/lib/pub.dart
@@ -18,8 +18,12 @@
///
/// If [analytics] is given, pub will use that analytics instance to send
/// statistics about resolutions.
-Command<int> pubCommand({PubAnalytics? analytics}) =>
- PubEmbeddableCommand(analytics);
+///
+/// [isVerbose] should return `true` (after argument resolution) if the
+/// embedding top-level is in verbose mode.
+Command<int> pubCommand(
+ {PubAnalytics? analytics, required bool Function() isVerbose}) =>
+ PubEmbeddableCommand(analytics, isVerbose);
/// Support for the `pub` toplevel command.
@Deprecated('Use [pubCommand] instead.')
diff --git a/lib/src/pub_embeddable_command.dart b/lib/src/pub_embeddable_command.dart
index a46e3f5..b9e59c6 100644
--- a/lib/src/pub_embeddable_command.dart
+++ b/lib/src/pub_embeddable_command.dart
@@ -58,11 +58,13 @@
@override
final PubAnalytics? analytics;
- PubEmbeddableCommand(this.analytics) : super() {
+ final bool Function() isVerbose;
+
+ PubEmbeddableCommand(this.analytics, this.isVerbose) : super() {
argParser.addFlag('trace',
help: 'Print debugging information when an error occurs.');
argParser.addFlag('verbose',
- abbr: 'v', negatable: false, help: 'Shortcut for "--verbosity=all".');
+ abbr: 'v', negatable: false, help: 'Print detailed logging.');
argParser.addOption(
'directory',
abbr: 'C',
@@ -101,12 +103,15 @@
}
@override
- bool get captureStackChains => argResults['verbose'];
+ bool get captureStackChains => _isVerbose;
@override
- Verbosity get verbosity =>
- argResults['verbose'] ? Verbosity.all : Verbosity.normal;
+ Verbosity get verbosity => _isVerbose ? Verbosity.all : Verbosity.normal;
@override
- bool get trace => argResults['verbose'];
+ bool get trace => _isVerbose;
+
+ bool get _isVerbose {
+ return argResults['verbose'] || isVerbose();
+ }
}
diff --git a/test/embedding/embedding_test.dart b/test/embedding/embedding_test.dart
index a24d5d5..a9795ea 100644
--- a/test/embedding/embedding_test.dart
+++ b/test/embedding/embedding_test.dart
@@ -221,6 +221,13 @@
// Don't write the logs to file on a normal run.
expect(File(logFile).existsSync(), isFalse);
});
+
+ test('`embedding --verbose pub` is verbose', () async {
+ await servePackages();
+ final buffer = StringBuffer();
+ await runEmbeddingToBuffer(['--verbose', 'pub', 'logout'], buffer);
+ expect(buffer.toString(), contains('FINE: Pub 0.1.2+3'));
+ });
}
String _filter(String input) {
diff --git a/tool/test-bin/pub_command_runner.dart b/tool/test-bin/pub_command_runner.dart
index 206a95b..e438aae 100644
--- a/tool/test-bin/pub_command_runner.dart
+++ b/tool/test-bin/pub_command_runner.dart
@@ -42,7 +42,9 @@
dependencyKindCustomDimensionName: 'cd1')
: null;
addCommand(
- pubCommand(analytics: analytics)..addSubcommand(ThrowingCommand()));
+ pubCommand(analytics: analytics, isVerbose: () => _options['verbose'])
+ ..addSubcommand(ThrowingCommand()));
+ argParser.addFlag('verbose');
}
@override