Hejsil / zig-clap

Command line argument parsing library
MIT License
939 stars 67 forks source link

README examples need an update #11

Closed SamTebbs33 closed 5 years ago

SamTebbs33 commented 5 years ago

The examples in the README seem to need an update, since I get errors saying container 'zig-clap.src.streaming.StreamingClap(u8,zig-clap.src.args.OsIterator)' has no member called 'init' and error: container 'zig-clap.clap.Param(u8)' has no member called 'flag' when replicating the examples. My source is below:

const std = @import("std");
const clap = @import("zig-clap/clap.zig");

const params = []clap.Param(u8) {
    clap.Param(u8).flag('h', clap.Names.both("help"))
};

pub fn main() !u8 {
    var direct_allocator = std.heap.DirectAllocator.init();
    defer direct_allocator.deinit();
    var arena_allocator = std.heap.ArenaAllocator.init(&direct_allocator.allocator);
    defer arena_allocator.deinit();

    const allocator = &arena_allocator.allocator;
    var iter = clap.args.OsIterator.init(allocator);
    defer iter.deinit();
    const executable = iter.next() catch unreachable;

    var parser = clap.StreamingClap(u8, clap.args.OsIterator).init(params, &iter);
    defer parser.deinit();

    while (try parser.next()) |arg| {
        switch (arg.param.id) {
            'h' => std.debug.warn("help\n"),
            else => unreachable
        }
    }
}
Hejsil commented 5 years ago

Aaah, you're right. After Zig got default values in structs, I decided to remove a lot of helper functions, and forgot to update the README. Updated examples can be found in the examples folder.

I'll update the README in a bit :)

SamTebbs33 commented 5 years ago

Thanks, I'll take a look at the examples folder :)

sagehane commented 3 years ago

I figured I might mention this here. std.debug.warn seems to be deprecated so I feel like the README should be updated to reflect that.

Hejsil commented 3 years ago

@sagehane Fixed in above commit. Next time, just open a new issue thanks :)