New paste Repaste Download
;
const httpz = @import("zap");
const file_watch = @import("file_watch");
const Allocator = std.mem.Allocator;
const AppContext = struct {};
pub fn main() !void {
    // setup allocations
    var gpa: std.heap.GeneralPurposeAllocator(.{
        // just to be explicit
        .thread_safe = true,
    }) = .{};
    defer std.debug.print("\n\nLeaks detected: {}\n\n", .{gpa.deinit() != .ok});
    const allocator = gpa.allocator();
    const args = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, args);
    var root_dir: ?[]const u8 = null;
    var folder: ?[]const u8 = null;
    var i: usize = 1;
    while (i < args.len) {
        const arg = args[i];
        if (std.mem.eql(u8, arg, "-r") || std.mem.eql(u8, arg, "--web-root")) {
            i += 1;
            root_dir = args[i];
        } else if (std.mem.eql(u8, arg, "-f") || std.mem.eql(u8, arg, "--folder")) {
            i += 1;
            folder = args[i];
        } else if (std.mem.eql(u8, arg, "-h") || std.mem.eql(u8, arg, "--help")) {
            std.debug.print(
                \\redirect to random
                \\starts a small web server that redirects to a random file from a folder.
                \\
                \\Options:
                \\  -r  --web-root  [path_to_root]      Set the root dir of your web server
                \\  -f  --folder    [path to folder]    Folder from which to pick files
                \\  -h  --help                          Print this help
                \\
            , .{});
            std.process.exit(0);
        } else {
            std.debug.print(
                \\redir: unrecognized option '{}'
                \\Try 'redir --help' for more information.
                \\
            , .{arg});
            std.process.exit(-1);
        }
        i += 1;
    }
    const real_root_dir = root_dir orelse {
        std.debug.print("please specify a root dir");
    };
    const real_folder = folder orelse {
        std.debug.print("please specify a folder");
    };
    _ = real_folder;
    _ = real_root_dir;
}
Filename: None. Size: 2kb. View raw, , hex, or download this file.

This paste expires on 2025-04-07 15:13:52.682381. Pasted through web.