From 64aab6048a2f9ae05ccecb6c9d9c56c46f4d589d Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 20 Feb 2024 20:05:05 +0100 Subject: [PATCH] feat: add more useful message if no parser was found --- src/main.zig | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 6ff0233..d3111ee 100644 --- a/src/main.zig +++ b/src/main.zig @@ -74,11 +74,18 @@ pub fn main() !void { try bw.flush(); } -fn render_file(a: std.mem.Allocator, writer: anytype, content: []const u8, file_path: []const u8, theme: *const Theme) !void { - const parser = if (lang_override) |name| - try syntax.create_file_type(a, content, name) +fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8) *syntax { + return (if (lang_override) |name| + syntax.create_file_type(a, content, name) else - try syntax.create_guess_file_type(a, content, file_path); + syntax.create_guess_file_type(a, content, file_path)) catch { + std.io.getStdErr().writer().writeAll("unknown file type. override with --lang\n") catch {}; + std.os.exit(1); + }; +} + +fn render_file(a: std.mem.Allocator, writer: anytype, content: []const u8, file_path: []const u8, theme: *const Theme) !void { + const parser = get_parser(a, content, file_path); const Ctx = struct { writer: @TypeOf(writer),