Use the exitCode attribute rather than exit().

This commit is contained in:
Natalie Weizenbaum 2016-11-02 17:57:55 -07:00
parent 6da45c827d
commit 805ce12e84
4 changed files with 14 additions and 9 deletions

View File

@ -33,7 +33,7 @@ void main(List<String> args) {
if (options['version'] as bool) {
_loadVersion().then((version) {
print(version);
exit(0);
exitCode = 0;
});
return;
}
@ -42,7 +42,8 @@ void main(List<String> args) {
print("Compile Sass to CSS.\n");
print("Usage: dart-sass <input>\n");
print(argParser.usage);
exit(64);
exitCode = 64;
return;
}
var color = options['color'] as bool;
@ -60,7 +61,7 @@ void main(List<String> args) {
// Exit code 65 indicates invalid data per
// http://www.freebsd.org/cgi/man.cgi?query=sysexits.
exit(65);
exitCode = 65;
} catch (error, stackTrace) {
if (color) stderr.write('\u001b[31m\u001b[1m');
stderr.write('Unexpected exception:');
@ -71,6 +72,7 @@ void main(List<String> args) {
stderr.writeln();
stderr.write(new Trace.from(stackTrace).terse.toString());
stderr.flush();
exitCode = 255;
}
}

View File

@ -26,5 +26,5 @@ String readFile(String path) => null;
/// Returns whether a file at [path] exists.
bool fileExists(String path) => null;
/// Exits the process with the given [exitCode].
void exit(int exitCode) {}
/// Gets and sets the exit code that the process will use when it exits.
int exitCode;

View File

@ -44,5 +44,8 @@ external _Stderr get _stderr;
final stderr = new Stderr(_stderr);
@JS("process.exit")
external int exit(int exitCode);
@JS("process.exitCode")
external int get exitCode;
@JS("process.exitCode")
external set exitCode(int code);

View File

@ -4,10 +4,10 @@
import 'dart:io' as io;
export 'dart:io' show exitCode;
io.Stdout get stderr => io.stderr;
String readFile(String path) => new io.File(path).readAsStringSync();
bool fileExists(String path) => new io.File(path).existsSync();
void exit(int exitCode) => io.exit(exitCode);