const std = @import("std"); const builtin = @import("builtin"); const zits = @import("zits"); const Message = zits.MessageParser.Message; const Server = zits.Server; const serve = @import("./subcommand/serve.zig").main; const help = \\High Performance NATS compatible client and server. \\ \\Commands: \\ serve Serve a high performance NATS compatible server \\ publish Publish a message over the NATS protocol \\ help Show this output \\ \\Global Flags: \\ -h, --help Show context-sensitive help \\ ; const Subcommand = enum { serve, publish, help, }; const to_subcommand: std.StaticStringMap(Subcommand) = .initComptime(.{ .{ @tagName(.serve), .serve }, .{ "srv", .serve }, .{ @tagName(.publish), .publish }, .{ "pub", .publish }, .{ @tagName(.help), .help }, }); pub fn main(init: std.process.Init) !void { const io = init.io; const args = try init.minimal.args.toSlice(init.arena.allocator()); if (args.len == 1) { try std.Io.File.stdout().writeStreamingAll(io, help); return; } switch (to_subcommand.get(args[1]) orelse .help) { .serve => { try serve(init.gpa, io, args[2..]); return; }, .publish => { std.debug.print("Unimplemented\n", .{}); }, else => { try std.Io.File.stdout().writeStreamingAll(io, help); return; }, } } pub const std_options: std.Options = .{ // By default, in safe build modes, the standard library will attach a segfault handler to the program to // print a helpful stack trace if a segmentation fault occurs. Here, we can disable this, or even enable // it in unsafe build modes. .enable_segfault_handler = true, // This is the logging function used by `std.log`. .logFn = myLogFn, }; fn myLogFn( comptime level: std.log.Level, comptime scope: @EnumLiteral(), comptime format: []const u8, args: anytype, ) void { if (scope == .zits) { std.log.defaultLog(level, std.log.default_log_scope, format, args); } else { std.log.defaultLog(level, scope, format, args); } }