Skip to content

Commit a677c24

Browse files
devoncarewcommit-bot@chromium.org
authored andcommitted
[dartdev] introduce a hidden --diagnostics flag
Change-Id: I129b350ef993f718fc2baecfa4af05b825d4e953 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153301 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Devon Carew <[email protected]>
1 parent c5ea3e8 commit a677c24

File tree

10 files changed

+50
-47
lines changed

10 files changed

+50
-47
lines changed

pkg/dartdev/lib/dartdev.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class DartdevRunner<int> extends CommandRunner {
145145
final bool verbose = args.contains('-v') || args.contains('--verbose');
146146

147147
argParser.addFlag('verbose',
148-
abbr: 'v', negatable: false, help: 'Show verbose output.');
148+
abbr: 'v', negatable: false, help: 'Show additional command output.');
149149
argParser.addFlag('version',
150150
negatable: false, help: 'Print the Dart SDK version.');
151151
argParser.addFlag('enable-analytics',
@@ -155,6 +155,9 @@ class DartdevRunner<int> extends CommandRunner {
155155

156156
addExperimentalFlags(argParser, verbose);
157157

158+
argParser.addFlag('diagnostics',
159+
negatable: false, help: 'Show tool diagnostic output.', hide: !verbose);
160+
158161
// A hidden flag to disable analytics on this run, this constructor can be
159162
// called with this flag, but should be removed before run() is called as
160163
// the flag has not been added to all sub-commands.
@@ -163,14 +166,14 @@ class DartdevRunner<int> extends CommandRunner {
163166
help: 'Disable anonymous analytics for this `dart *` run',
164167
hide: true);
165168

166-
addCommand(AnalyzeCommand(verbose: verbose));
169+
addCommand(AnalyzeCommand());
167170
addCommand(CreateCommand(verbose: verbose));
168-
addCommand(CompileCommand(verbose: verbose));
169-
addCommand(FormatCommand(verbose: verbose));
171+
addCommand(CompileCommand());
172+
addCommand(FormatCommand());
170173
addCommand(MigrateCommand(verbose: verbose));
171-
addCommand(PubCommand(verbose: verbose));
172-
addCommand(RunCommand(verbose: verbose));
173-
addCommand(TestCommand(verbose: verbose));
174+
addCommand(PubCommand());
175+
addCommand(RunCommand());
176+
addCommand(TestCommand());
174177
}
175178

176179
@override
@@ -192,13 +195,16 @@ class DartdevRunner<int> extends CommandRunner {
192195
io.exit(254);
193196
}
194197
}
195-
isVerbose = topLevelResults['verbose'];
198+
199+
isDiagnostics = topLevelResults['diagnostics'];
196200

197201
final Ansi ansi = Ansi(Ansi.terminalSupportsAnsi);
198-
log = isVerbose ? Logger.verbose(ansi: ansi) : Logger.standard(ansi: ansi);
202+
log = isDiagnostics
203+
? Logger.verbose(ansi: ansi)
204+
: Logger.standard(ansi: ansi);
199205

200-
if (wereExperimentsSpecified(topLevelResults)) {
201-
List<String> experimentIds = specifiedExperiments(topLevelResults);
206+
if (topLevelResults.wasParsed(experimentFlagName)) {
207+
List<String> experimentIds = topLevelResults[experimentFlagName];
202208
for (ExperimentalFeature feature in experimentalFeatures) {
203209
// We allow default true flags, but complain when they are passed in.
204210
if (feature.isEnabledByDefault &&

pkg/dartdev/lib/src/commands/analyze.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import 'analyze_impl.dart';
1515
// TODO: Support enable-experiment for 'dart analyze'.
1616

1717
class AnalyzeCommand extends DartdevCommand<int> {
18-
AnalyzeCommand({bool verbose = false})
19-
: super('analyze', "Analyze the project's Dart code.") {
18+
AnalyzeCommand() : super('analyze', "Analyze the project's Dart code.") {
2019
argParser
2120
..addFlag('fatal-infos',
2221
help: 'Treat info level issues as fatal.', negatable: false)
@@ -104,6 +103,9 @@ class AnalyzeCommand extends DartdevCommand<int> {
104103
'(${error.code})',
105104
);
106105

106+
// TODO(devoncarew): If verbose, print additional information about the
107+
// issue (resolution, more info url, ...).
108+
107109
hasErrors |= error.isError;
108110
hasWarnings |= error.isWarning;
109111
hasInfos |= error.isInfo;

pkg/dartdev/lib/src/commands/analyze_impl.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class AnalysisServer {
4545
sdkPath.path,
4646
];
4747

48-
log.trace('dart ${command.join(' ')}');
4948
_process = await startProcess(sdk.dart, command);
5049
// This callback hookup can't throw.
5150
//ignore: unawaited_futures

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Option {
1818
final String flag;
1919
final String help;
2020
final String abbr;
21+
2122
Option({this.flag, this.help, this.abbr});
2223
}
2324

@@ -44,10 +45,7 @@ bool checkFile(String sourcePath) {
4445
}
4546

4647
class CompileJSCommand extends DartdevCommand<int> {
47-
bool verbose = false;
48-
CompileJSCommand({
49-
this.verbose,
50-
}) : super('js', 'Compile Dart to JavaScript') {
48+
CompileJSCommand() : super('js', 'Compile Dart to JavaScript') {
5149
argParser
5250
..addOption(
5351
commonOptions['outputFile'].flag,
@@ -85,14 +83,12 @@ class CompileJSCommand extends DartdevCommand<int> {
8583
}
8684

8785
class CompileSnapshotCommand extends DartdevCommand<int> {
88-
bool verbose = false;
8986
final String commandName;
9087
final String help;
9188
final String fileExt;
9289
final String formatName;
9390

9491
CompileSnapshotCommand({
95-
this.verbose,
9692
this.commandName,
9793
this.help,
9894
this.fileExt,
@@ -146,13 +142,11 @@ class CompileSnapshotCommand extends DartdevCommand<int> {
146142
}
147143

148144
class CompileNativeCommand extends DartdevCommand<int> {
149-
bool verbose = false;
150145
final String commandName;
151146
final String format;
152147
final String help;
153148

154149
CompileNativeCommand({
155-
this.verbose,
156150
this.commandName,
157151
this.format,
158152
this.help,
@@ -216,29 +210,27 @@ Remove debugging information from the output and save it separately to the speci
216210
class CompileCommand extends Command {
217211
@override
218212
String get description => 'Compile Dart to various formats.';
213+
219214
@override
220215
String get name => 'compile';
221216

222-
CompileCommand({bool verbose = false}) {
217+
CompileCommand() {
223218
addSubcommand(CompileJSCommand());
224219
addSubcommand(CompileSnapshotCommand(
225220
commandName: 'jit-snapshot',
226221
help: 'to a JIT snapshot',
227222
fileExt: 'jit',
228223
formatName: 'app-jit',
229-
verbose: verbose,
230224
));
231225
addSubcommand(CompileNativeCommand(
232226
commandName: 'exe',
233227
help: 'to a self-contained executable',
234228
format: 'exe',
235-
verbose: verbose,
236229
));
237230
addSubcommand(CompileNativeCommand(
238231
commandName: 'aot-snapshot',
239232
help: 'to an AOT snapshot',
240233
format: 'aot',
241-
verbose: verbose,
242234
));
243235
}
244236
}

pkg/dartdev/lib/src/commands/format.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import '../core.dart';
88
import '../sdk.dart';
99

1010
class FormatCommand extends DartdevCommand {
11-
FormatCommand({bool verbose = false})
12-
: super('format', 'Format Dart source code.') {
11+
FormatCommand() : super('format', 'Format Dart source code.') {
1312
// TODO(jwren) When https://github.com/dart-lang/dart_style/issues/889
1413
// is resolved, have dart_style provide the ArgParser, instead of creating
1514
// one here.

pkg/dartdev/lib/src/commands/pub.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../experiments.dart';
1212
import '../sdk.dart';
1313

1414
class PubCommand extends DartdevCommand<int> {
15-
PubCommand({bool verbose = false}) : super('pub', 'Work with packages.');
15+
PubCommand() : super('pub', 'Work with packages.');
1616

1717
@override
1818
final ArgParser argParser = ArgParser.allowAnything();
@@ -46,8 +46,8 @@ class PubCommand extends DartdevCommand<int> {
4646
var args = argResults.arguments;
4747

4848
// Pass any --enable-experiment options along.
49-
if (args.isNotEmpty && wereExperimentsSpecified(globalResults)) {
50-
List<String> experimentIds = specifiedExperiments(globalResults);
49+
if (args.isNotEmpty && wereExperimentsSpecified) {
50+
List<String> experimentIds = specifiedExperiments;
5151

5252
if (args.first == 'run') {
5353
args = [

pkg/dartdev/lib/src/commands/run.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import '../utils.dart';
1818
class RunCommand extends DartdevCommand<int> {
1919
@override
2020
final ArgParser argParser = ArgParser.allowAnything();
21+
22+
@override
2123
final bool verbose;
2224

2325
RunCommand({this.verbose = false}) : super('run', '''
@@ -102,9 +104,8 @@ Run a Dart file.''');
102104
}
103105

104106
// Pass any --enable-experiment options along.
105-
// todo: test
106-
if (args.isNotEmpty && wereExperimentsSpecified(globalResults)) {
107-
List<String> experimentIds = specifiedExperiments(globalResults);
107+
if (args.isNotEmpty && wereExperimentsSpecified) {
108+
List<String> experimentIds = specifiedExperiments;
108109
args = [
109110
'--$experimentFlagName=${experimentIds.join(',')}',
110111
...args,

pkg/dartdev/lib/src/commands/test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import '../core.dart';
1111
import '../sdk.dart';
1212

1313
class TestCommand extends DartdevCommand<int> {
14-
TestCommand({bool verbose = false})
15-
: super('test', 'Runs tests in this project.');
14+
TestCommand() : super('test', 'Runs tests in this project.');
1615

1716
@override
1817
final ArgParser argParser = ArgParser.allowAnything();

pkg/dartdev/lib/src/core.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import 'package:args/command_runner.dart';
99
import 'package:cli_util/cli_logging.dart';
1010
import 'package:path/path.dart' as path;
1111

12+
import 'experiments.dart';
1213
import 'utils.dart';
1314

1415
Logger log;
15-
bool isVerbose = false;
16+
bool isDiagnostics = false;
1617

1718
abstract class DartdevCommand<int> extends Command {
1819
final String _name;
@@ -32,6 +33,19 @@ abstract class DartdevCommand<int> extends Command {
3233
String get description => _description;
3334

3435
Project get project => _project ??= Project();
36+
37+
/// Return whether commands should emit verbose output.
38+
bool get verbose => globalResults['verbose'];
39+
40+
/// Return whether the tool should emit diagnostic output.
41+
bool get diagnosticsEnabled => globalResults['diagnostics'];
42+
43+
/// Return whether any Dart experiments were specified by the user.
44+
bool get wereExperimentsSpecified =>
45+
globalResults.wasParsed(experimentFlagName);
46+
47+
/// Return the list of Dart experiment flags specified by the user.
48+
List<String> get specifiedExperiments => globalResults[experimentFlagName];
3549
}
3650

3751
/// A utility method to start the given executable as a process, optionally
@@ -50,7 +64,7 @@ void routeToStdout(
5064
bool logToTrace = false,
5165
void Function(String str) listener,
5266
}) {
53-
if (isVerbose) {
67+
if (isDiagnostics) {
5468
_streamLineTransform(process.stdout, (String line) {
5569
logToTrace ? log.trace(line.trimRight()) : log.stdout(line.trimRight());
5670
if (listener != null) listener(line);

pkg/dartdev/lib/src/experiments.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/src/dart/analysis/experiments.dart';
6-
import 'package:args/args.dart';
76

87
const experimentFlagName = 'enable-experiment';
98

@@ -15,11 +14,3 @@ List<ExperimentalFeature> get experimentalFeatures {
1514
features.sort((a, b) => a.enableString.compareTo(b.enableString));
1615
return features;
1716
}
18-
19-
/// Return whether any Dart experiments were specified by the user.
20-
bool wereExperimentsSpecified(ArgResults argResults) =>
21-
argResults.wasParsed(experimentFlagName);
22-
23-
/// Return the list of Dart experiment flags specified by the user.
24-
List<String> specifiedExperiments(ArgResults argResults) =>
25-
argResults[experimentFlagName];

0 commit comments

Comments
 (0)