feat: add more useful message if no parser was found

This commit is contained in:
CJ van den Berg 2024-02-20 20:05:05 +01:00
parent 2ad1ae7c02
commit 64aab6048a

View file

@ -74,11 +74,18 @@ pub fn main() !void {
try bw.flush(); try bw.flush();
} }
fn render_file(a: std.mem.Allocator, writer: anytype, content: []const u8, file_path: []const u8, theme: *const Theme) !void { fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8) *syntax {
const parser = if (lang_override) |name| return (if (lang_override) |name|
try syntax.create_file_type(a, content, name) syntax.create_file_type(a, content, name)
else 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 { const Ctx = struct {
writer: @TypeOf(writer), writer: @TypeOf(writer),