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 multiple positionals of different type #98

Open
aherrmann opened this issue Jun 16, 2023 · 1 comment
Open

Support for multiple positionals of different type #98

aherrmann opened this issue Jun 16, 2023 · 1 comment

Comments

@aherrmann
Copy link
Contributor

#97 (comment)

For example <u32> <string>... will make the positionals field in the result be []const u32, ignoring that the other positional parameter specified string.

@michidk
Copy link

michidk commented Dec 27, 2023

I thought this meant, that I can specify it as <u16> in the help and then parse the []const u32 into a u16 by hand.

But it actually does not even compile.
This:

    const params = comptime clap.parseParamsComptime(
        \\-h, --help                   Display this help.
        \\<str>                     	The host to connect to.
        \\<u16>                     	The port to connect to.
        \\
    );

, gives the following error:

vscode ➜ /workspaces/my-project (main) $ zig build
zig build-exe my-project Debug native: error: the following command failed with 1 compilation errors:
/usr/local/lib/zig/zig build-exe /workspaces/my-project/src/main.zig --cache-dir /workspaces/my-project/zig-cache --global-cache-dir /home/vscode/.cache/zig --name my-project --mod clap::/home/vscode/.cache/zig/p/1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2/clap.zig --deps clap --listen=- 
Build Summary: 0/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run my-project transitive failure
   ├─ zig build-exe my-project Debug native 1 errors
   └─ install transitive failure
      └─ install my-project transitive failure
         └─ zig build-exe my-project Debug native (reused)
/home/vscode/.cache/zig/p/1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2/clap.zig:813:47: error: expected type '[]const u8', found 'u16'
        .positional => try positionals.append(try parser(arg.value.?)),
                                              ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/zig/lib/std/array_list.zig:206:42: note: parameter type declared here
        pub fn append(self: *Self, item: T) Allocator.Error!void {

So the only way I can make this work is by using <str> for both.

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