Skip to content

Commit 41b5c49

Browse files
authored
Merge pull request #1036 from dart-lang/stdin-exit-code
Return correct exit code from FormatCommand when formatting stdin.
2 parents 5f93e07 + d173368 commit 41b5c49

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2.0.2-dev
22

33
* Don't unnecessarily split argument lists with `/* */` comments (#837).
4+
* Return correct exit code from `FormatCommand` when formatting stdin (#1035).
45

56
# 2.0.1
67

bin/format.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:dart_style/src/cli/summary.dart';
1212
import 'package:dart_style/src/io.dart';
1313
import 'package:dart_style/src/style_fix.dart';
1414

15-
void main(List<String> args) {
15+
void main(List<String> args) async {
1616
var parser = ArgParser(allowTrailingOptions: true);
1717

1818
defineOptions(parser,
@@ -135,7 +135,7 @@ void main(List<String> args) {
135135
setExitIfChanged: setExitIfChanged);
136136

137137
if (argResults.rest.isEmpty) {
138-
formatStdin(options, selection, argResults['stdin-name'] as String);
138+
await formatStdin(options, selection, argResults['stdin-name'] as String);
139139
} else {
140140
formatPaths(options, argResults.rest);
141141
}

lib/src/cli/format_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class FormatCommand extends Command<int> {
152152
setExitIfChanged: setExitIfChanged);
153153

154154
if (argResults.rest.isEmpty) {
155-
formatStdin(options, selection, stdinName);
155+
await formatStdin(options, selection, stdinName);
156156
} else {
157157
formatPaths(options, argResults.rest);
158158
options.summary.show();

lib/src/io.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4-
5-
library dart_style.src.io;
6-
4+
import 'dart:async';
75
import 'dart:convert';
86
import 'dart:io';
97

@@ -15,7 +13,8 @@ import 'exceptions.dart';
1513
import 'source_code.dart';
1614

1715
/// Reads and formats input from stdin until closed.
18-
void formatStdin(FormatterOptions options, List<int>? selection, String name) {
16+
Future<void> formatStdin(
17+
FormatterOptions options, List<int>? selection, String name) async {
1918
var selectionStart = 0;
2019
var selectionLength = 0;
2120

@@ -24,6 +23,7 @@ void formatStdin(FormatterOptions options, List<int>? selection, String name) {
2423
selectionLength = selection[1];
2524
}
2625

26+
var completer = Completer<void>();
2727
var input = StringBuffer();
2828
stdin.transform(Utf8Decoder()).listen(input.write, onDone: () {
2929
var formatter = DartFormatter(
@@ -50,7 +50,11 @@ $err
5050
$stack''');
5151
exitCode = 70; // sysexits.h: EX_SOFTWARE
5252
}
53+
54+
completer.complete();
5355
});
56+
57+
return completer.future;
5458
}
5559

5660
/// Formats all of the files and directories given by [paths].

0 commit comments

Comments
 (0)