Skip to content

Commit ea56fcd

Browse files
authored
some cleanup to the stdout messages we print (#1413)
1 parent b353c7b commit ea56fcd

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

bin/dartdoc.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ main(List<String> arguments) async {
4040

4141
Directory sdkDir = getSdkDir();
4242
if (sdkDir == null) {
43-
stderr.write(" Error: unable to locate the Dart SDK.");
43+
stderr.writeln(" Error: unable to locate the Dart SDK.");
4444
exit(1);
4545
}
4646

@@ -55,14 +55,14 @@ main(List<String> arguments) async {
5555

5656
var readme = args['sdk-readme'];
5757
if (readme != null && !(new File(readme).existsSync())) {
58-
stderr.write(
58+
stderr.writeln(
5959
" fatal error: unable to locate the SDK description file at $readme.");
6060
exit(1);
6161
}
6262

6363
Directory inputDir = new Directory(args['input']);
6464
if (!inputDir.existsSync()) {
65-
stderr.write(
65+
stderr.writeln(
6666
" fatal error: unable to locate the input directory at ${inputDir.path}.");
6767
exit(1);
6868
}
@@ -77,7 +77,7 @@ main(List<String> arguments) async {
7777
args['header'].map(_resolveTildePath).toList() as List<String>;
7878
for (String headerFilePath in headerFilePaths) {
7979
if (!new File(headerFilePath).existsSync()) {
80-
stderr.write(
80+
stderr.writeln(
8181
" fatal error: unable to locate header file: ${headerFilePath}.");
8282
exit(1);
8383
}
@@ -87,7 +87,7 @@ main(List<String> arguments) async {
8787
args['footer'].map(_resolveTildePath).toList() as List<String>;
8888
for (String footerFilePath in footerFilePaths) {
8989
if (!new File(footerFilePath).existsSync()) {
90-
stderr.write(
90+
stderr.writeln(
9191
" fatal error: unable to locate footer file: ${footerFilePath}.");
9292
exit(1);
9393
}
@@ -97,7 +97,7 @@ main(List<String> arguments) async {
9797
args['footer-text'].map(_resolveTildePath).toList() as List<String>;
9898
for (String footerFilePath in footerTextFilePaths) {
9999
if (!new File(footerFilePath).existsSync()) {
100-
stderr.write(
100+
stderr.writeln(
101101
" fatal error: unable to locate footer-text file: ${footerFilePath}.");
102102
exit(1);
103103
}
@@ -111,7 +111,7 @@ main(List<String> arguments) async {
111111

112112
if (args.rest.isNotEmpty) {
113113
var unknownArgs = args.rest.join(' ');
114-
stderr.write(
114+
stderr.writeln(
115115
' fatal error: detected unknown command-line argument(s): $unknownArgs');
116116
_printUsageAndExit(parser, exitCode: 1);
117117
}

lib/dartdoc.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:analyzer/src/generated/java_io.dart';
2121
import 'package:analyzer/src/generated/sdk.dart';
2222
import 'package:analyzer/src/generated/source.dart';
2323
import 'package:analyzer/src/generated/source_io.dart';
24+
import 'package:dartdoc/src/utils.dart';
2425
import 'package:html/dom.dart' show Element, Document;
2526
import 'package:html/parser.dart' show parse;
2627
import 'package:package_config/discovery.dart' as package_config;
@@ -173,9 +174,6 @@ class DartDoc {
173174
}
174175
package = new Package(libraries, packageMeta, warningOptions);
175176

176-
print(
177-
'\ngenerating docs for libraries ${package.libraries.map((Library l) => l.name).join(', ')}\n');
178-
179177
// Go through docs of every model element in package to prebuild the macros index
180178
// TODO(jcollins-g): move index building into a cached-on-demand generation
181179
// like most other bits in [Package].
@@ -189,14 +187,21 @@ class DartDoc {
189187
writtenFiles.addAll(generator.writtenFiles.map(path.normalize));
190188
}
191189

192-
verifyLinks(package, outputDir.path);
193-
194190
double seconds = _stopwatch.elapsedMilliseconds / 1000.0;
195191
print(
196-
"\nDocumented ${package.libraries.length} librar${package.libraries.length == 1 ? 'y' : 'ies'} "
197-
"in ${seconds.toStringAsFixed(1)} seconds.");
198-
print(
199-
"Finished with: ${package.packageWarningCounter.warningCount} warnings, ${package.packageWarningCounter.errorCount} errors");
192+
"documented ${package.libraries.length} librar${package.libraries.length == 1 ? 'y' : 'ies'} "
193+
"in ${seconds.toStringAsFixed(1)} seconds");
194+
print('');
195+
196+
verifyLinks(package, outputDir.path);
197+
int warnings = package.packageWarningCounter.warningCount;
198+
int errors = package.packageWarningCounter.errorCount;
199+
if (warnings == 0 && errors == 0) {
200+
print("no issues found");
201+
} else {
202+
print("found ${warnings} ${pluralize('warning', warnings)} "
203+
"and ${errors} ${pluralize('error', errors)}");
204+
}
200205

201206
if (package.libraries.isEmpty) {
202207
throw new DartDocFailure(
@@ -351,7 +356,7 @@ class DartDoc {
351356
final Set<String> visited = new Set();
352357
final String start = 'index.html';
353358
visited.add(start);
354-
stdout.write('\nvalidating docs');
359+
print('validating docs...');
355360
_doCheck(package, origin, visited, start);
356361
_doOrphanCheck(package, origin, visited);
357362
}
@@ -510,9 +515,10 @@ class DartDoc {
510515
..sort();
511516

512517
double seconds = _stopwatch.elapsedMilliseconds / 1000.0;
513-
print("Parsed ${libraries.length} "
514-
"file${libraries.length == 1 ? '' : 's'} in "
515-
"${seconds.toStringAsFixed(1)} seconds.\n");
518+
print("parsed ${libraries.length} ${pluralize('file', libraries.length)} "
519+
"in ${seconds.toStringAsFixed(1)} seconds");
520+
print('');
521+
_stopwatch.reset();
516522

517523
if (errors.isNotEmpty) {
518524
errors.forEach(print);

lib/src/html/html_generator_instance.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'dart:async' show Future, StreamController;
66
import 'dart:convert' show JsonEncoder;
7-
import 'dart:io' show Directory, File, stdout;
7+
import 'dart:io' show Directory, File;
88
import 'dart:typed_data' show Uint8List;
99

1010
import 'package:collection/collection.dart' show compareNatural;
@@ -178,16 +178,13 @@ class HtmlGeneratorInstance implements HtmlOptions {
178178
}
179179

180180
void generatePackage() {
181-
stdout.write('\ndocumenting ${package.name}');
182-
183181
TemplateData data = new PackageTemplateData(this, package, useCategories);
184182

185183
_build('index.html', _templates.indexTemplate, data);
186184
}
187185

188186
void generateLibrary(Package package, Library lib) {
189-
stdout
190-
.write('\ngenerating docs for library ${lib.name} from ${lib.path}...');
187+
print('generating docs for library ${lib.name} from ${lib.path}...');
191188
if (!lib.isAnonymous && !lib.hasDocumentation) {
192189
package.warnOnElement(lib, PackageWarning.noLibraryLevelDocs);
193190
}

lib/src/model.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ class PackageWarningCounter {
28492849
} else {
28502850
if (options.asErrors.contains(kind)) toWrite = "error: ${fullMessage}";
28512851
}
2852-
if (toWrite != null) stderr.write("\n ${toWrite}");
2852+
if (toWrite != null) print(" ${toWrite}");
28532853
}
28542854

28552855
/// Returns true if we've already warned for this.
@@ -3057,7 +3057,7 @@ class Package implements Nameable, Documentable {
30573057
break;
30583058
case PackageWarning.unknownFile:
30593059
warningMessage =
3060-
'dartdoc detected an unknown file in the doc tree: ${message}';
3060+
'dartdoc detected an unknown file in the doc tree: ${message}';
30613061
break;
30623062
case PackageWarning.typeAsHtml:
30633063
// The message for this warning can contain many punctuation and other symbols,

lib/src/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ String truncateString(String str, int length) {
4949
return str;
5050
}
5151
}
52+
53+
String pluralize(String word, int count) => count == 1 ? word : '${word}s';

0 commit comments

Comments
 (0)