Added cli options and help command, WIP readme update
This commit is contained in:
+21
-12
@@ -2,14 +2,19 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:dartboard_resume/render.dart';
|
||||
import 'package:dartboard_resume/utils.dart';
|
||||
import 'package:hotreloader/hotreloader.dart';
|
||||
import 'package:toml/toml.dart';
|
||||
|
||||
StreamSubscription<FileSystemEvent>? fileStreamSub;
|
||||
StreamSubscription<String>? stdinStreamSub;
|
||||
|
||||
Future<void> dartboardRun(HotReloader? reloader) async {
|
||||
const String tomlFilePath = "resume.toml";
|
||||
Future<void> dartboardRun(HotReloader? reloader, List<String> arguments) async {
|
||||
final result = getTomlFromArgs(arguments);
|
||||
if (!result.success) {
|
||||
exitRunner(reloader);
|
||||
}
|
||||
final resumeTomlFile = result.file!;
|
||||
|
||||
if (reloader != null) {
|
||||
stdout.writeln('Hot reload enabled!');
|
||||
@@ -17,22 +22,18 @@ Future<void> dartboardRun(HotReloader? reloader) async {
|
||||
|
||||
ProcessSignal.sigint.watch().listen((_) {
|
||||
stdout.writeln('SIGINT received. Exiting gracefully...');
|
||||
fileStreamSub?.cancel();
|
||||
stdinStreamSub?.cancel();
|
||||
// Perform cleanup or other necessary actions here
|
||||
reloader?.stop();
|
||||
exit(0); // Exit with code 0 to indicate a successful termination
|
||||
exitRunner(reloader);
|
||||
});
|
||||
|
||||
stdinStreamSub = getUserInputStream().listen(
|
||||
(event) {
|
||||
if (event == "r") {
|
||||
stdout.writeln("Triggering pdf render...");
|
||||
createDocument(tomlFilePath);
|
||||
createDocument(resumeTomlFile.path);
|
||||
}
|
||||
if (event == "p") {
|
||||
stdout.writeln("Current toml map:");
|
||||
stdout.writeln(TomlDocument.loadSync(tomlFilePath).toMap());
|
||||
stdout.writeln(TomlDocument.loadSync(resumeTomlFile.path).toMap());
|
||||
}
|
||||
if (event == "q") {
|
||||
stdout.writeln('Exiting...');
|
||||
@@ -46,14 +47,14 @@ Future<void> dartboardRun(HotReloader? reloader) async {
|
||||
);
|
||||
|
||||
if (FileSystemEntity.isWatchSupported) {
|
||||
final fileStream = File(tomlFilePath).watch(events: FileSystemEvent.modify);
|
||||
final fileStream = resumeTomlFile.watch(events: FileSystemEvent.modify);
|
||||
fileStreamSub = fileStream.listen((e) {
|
||||
createDocument(tomlFilePath);
|
||||
createDocument(resumeTomlFile.path);
|
||||
});
|
||||
stdout.writeln('Watching for file changes.');
|
||||
} else {
|
||||
stdout.writeln('File watch is not supported. Exiting upon completion.');
|
||||
createDocument(tomlFilePath);
|
||||
createDocument(resumeTomlFile.path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,3 +81,11 @@ void createDocument(String tomlFilePath) {
|
||||
renderPdf(tomlFilePath, force: true);
|
||||
refreshViewer();
|
||||
}
|
||||
|
||||
void exitRunner(HotReloader? reloader) {
|
||||
fileStreamSub?.cancel();
|
||||
stdinStreamSub?.cancel();
|
||||
// Perform cleanup or other necessary actions here
|
||||
reloader?.stop();
|
||||
exit(0); // Exit with code 0 to indicate a successful termination
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user