Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for more complex parameters #35

Open
maringuu opened this issue Dec 27, 2020 · 2 comments
Open

Support for more complex parameters #35

maringuu opened this issue Dec 27, 2020 · 2 comments

Comments

@maringuu
Copy link

I'd like to parse something like --mode <width>x<height>[@<refresh>Hz].
To my from my current understanding this is not possible.

I intended to write it as follows:

    const params = comptime [_]clap.Param(clap.Help) {
        .{
            .id = .{.msg = "defines the output mode", .value = "<width>x<height>[@<refresh>Hz]"},
            .names = .{ .short = 'm', .long = "mode" },
            .takes_value = .One,
        },
    };

    var args = try clap.parse(clap.Help, &params, std.heap.page_allocator, null);
    defer args.deinit();

    if (args.option("--mode")) |n| {
        // Parse width,height and refresh manually
    }

This would work but is to some extend a hack. The main problem with this is that all help* functions become useless because they put <> around the value string.

A simple fix would be to make the formatting in parseParam accept a custom formatstring. But I am not sure that this is the right solution.

When this usecase is considered valid then I'll spend some time thinking about a good solution.

@Hejsil
Copy link
Owner

Hejsil commented Dec 27, 2020

Aah, so this is a request for improving parseParam and help to support more exotic help "value descriptions" per say. Yea, if we can come up with something good, then I'm all for making this improvement 👍

@Hejsil
Copy link
Owner

Hejsil commented Dec 27, 2020

Ofc, you'll still need to handle parsing this format outside the library, but as far as I understand, that is your intention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants