Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes #8

Merged
merged 10 commits into from Oct 11, 2022
54 changes: 52 additions & 2 deletions bin/fire.dart
@@ -1,7 +1,8 @@
import 'dart:io' show FileSystemEntity, exit;
import 'dart:io' show FileSystemEntity, ProcessResult, exit, stdout;

import 'package:fire/fire.dart';
import 'package:fire/fire.dart' show FireOutputDelegate, run_fire;
import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart' show Trace;

Future<void> main(
final List<String> args,
Expand All @@ -19,10 +20,59 @@ Future<void> main(
args: [
if (args.isNotEmpty) ...args.sublist(1, args.length),
],
output: _FireOutputDelegateImpl(
output: stdout.writeln,
),
);
} else {
print("'" + file_path + "' not found or isn't a file.");
exit(2);
}
}
}

class _FireOutputDelegateImpl implements FireOutputDelegate {
final void Function(String) output;

const _FireOutputDelegateImpl({
required this.output,
});

@override
void output_error(
final Object payload,
final StackTrace stack_trace,
) {
output(payload.toString());
output(Trace.format(stack_trace));
}

@override
void output_string(
final String str,
) {
output(str);
}

@override
void output_compiler_output(
final Iterable<String> values,
) {
for (final line in values) {
output(line);
}
}

@override
void redirect_process(
final ProcessResult result,
) {
// TODO https://stackoverflow.com/questions/33251129/what-is-the-best-way-to-stream-stdout-from-a-process-in-dart
if (result.stdout != null) {
output(result.stdout.toString().trimRight());
}
if (result.stderr != null) {
output(result.stderr.toString().trimRight());
}
}
}