Added cli options and help command, WIP readme update

This commit is contained in:
Nate Anderson 2024-12-19 16:48:03 -07:00
parent fe40731e09
commit 65922f515a
7 changed files with 94 additions and 29 deletions

4
.gitignore vendored
View File

@ -1,7 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/ .dart_tool/
.direnv/** .direnv/**
bin/**
!bin/dartboard_resume.dart
*.toml *.toml
*.pdf *.pdf

View File

@ -1,2 +1,15 @@
A sample command-line application with an entrypoint in `bin/`, library code # Dartboard Resume
in `lib/`, and example unit test in `test/`.
## Installing
TODO
## Running
`dart run ./bin/dartboard_resume.dart`
or
## Creating Your Resume

View File

@ -17,5 +17,5 @@ Future<void> main(List<String> arguments) async {
"Dartboard can hot reload if run with dart's VM service.\n`dart run --enable-vm-service bin/dartboard_resume.dart`", "Dartboard can hot reload if run with dart's VM service.\n`dart run --enable-vm-service bin/dartboard_resume.dart`",
); );
} }
dartboardRun(reloader); dartboardRun(reloader, arguments);
} }

View File

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

View File

@ -1,5 +1,48 @@
import 'dart:io';
import 'package:args/args.dart';
extension StringUtils on String { extension StringUtils on String {
String capitalize() { String capitalize() {
return substring(0, 1).toUpperCase() + substring(1); return substring(0, 1).toUpperCase() + substring(1);
} }
} }
({bool success, File? file}) getTomlFromArgs(List<String> args) {
const String templateResumePath = 'assets/resume_template.toml';
final parser = ArgParser();
parser.addOption('input', abbr: 'i', defaultsTo: 'examples/resume.toml', help: 'Input file path');
parser.addFlag('help', abbr: 'h', help: 'Prints help info');
final parsedResults = parser.parse(args);
if (parsedResults.flag("help")) {
stdout.writeln(parser.usage);
return (success: false, file: null);
}
final inputFilePath = parsedResults.option('input');
if (inputFilePath == null) {
throw Exception('No valid input provided.');
}
final inputFile = File(inputFilePath);
if (!inputFile.existsSync()) {
stdout.writeln(
'Provided `$inputFilePath`, but it does not exist. Would you like to start with the template?\n\t($templateResumePath copied to $inputFilePath)\n(y/n): ',
);
final ans = stdin.readLineSync()?.toLowerCase() ?? 'n';
if (ans == 'y') {
stdout.writeln('Copying over...');
File(templateResumePath).copySync(inputFilePath);
final newFile = File(inputFilePath);
if (!newFile.existsSync()) {
return (success: false, file: null);
}
return (success: true, file: newFile);
} else {
stdout.writeln('Got it. Try again with an actual existing document. You got this 👍');
return (success: false, file: null);
}
} else {
return (success: true, file: inputFile);
}
}

View File

@ -5,23 +5,23 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: _fe_analyzer_shared name: _fe_analyzer_shared
sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77" sha256: "5aaf60d96c4cd00fe7f21594b5ad6a1b699c80a27420f8a837f4d68473ef09e3"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "73.0.0" version: "68.0.0"
_macros: _macros:
dependency: transitive dependency: transitive
description: dart description: dart
source: sdk source: sdk
version: "0.3.2" version: "0.1.0"
analyzer: analyzer:
dependency: transitive dependency: transitive
description: description:
name: analyzer name: analyzer
sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a" sha256: "21f1d3720fd1c70316399d5e2bccaebb415c434592d778cce8acb967b8578808"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.8.0" version: "6.5.0"
archive: archive:
dependency: transitive dependency: transitive
description: description:
@ -31,13 +31,13 @@ packages:
source: hosted source: hosted
version: "3.6.1" version: "3.6.1"
args: args:
dependency: transitive dependency: "direct main"
description: description:
name: args name: args
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.5.0" version: "2.6.0"
async: async:
dependency: transitive dependency: transitive
description: description:
@ -135,7 +135,7 @@ packages:
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
hotreloader: hotreloader:
dependency: "direct dev" dependency: "direct main"
description: description:
name: hotreloader name: hotreloader
sha256: ed56fdc1f3a8ac924e717257621d09e9ec20e308ab6352a73a50a1d7a4d9158e sha256: ed56fdc1f3a8ac924e717257621d09e9ec20e308ab6352a73a50a1d7a4d9158e
@ -218,10 +218,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: macros name: macros
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" sha256: "12e8a9842b5a7390de7a781ec63d793527582398d16ea26c60fed58833c9ae79"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.2-main.4" version: "0.1.0-main.0"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:

View File

@ -8,13 +8,13 @@ environment:
# Add regular dependencies here. # Add regular dependencies here.
dependencies: dependencies:
args: ^2.6.0
hotreloader: ^4.2.0 hotreloader: ^4.2.0
intl: ^0.19.0 intl: ^0.19.0
lint: ^2.3.0 lint: ^2.3.0
logging: ^1.2.0 logging: ^1.2.0
pdf: ^3.11.1 pdf: ^3.11.1
toml: ^0.16.0 toml: ^0.16.0
# path: ^1.8.0
dev_dependencies: dev_dependencies:
lints: ^3.0.0 lints: ^3.0.0