zig-clap
zig-clap copied to clipboard
Support for multiple positionals of different type
https://github.com/Hejsil/zig-clap/pull/97#issuecomment-1592545848
For example
<u32> <string>...will make thepositionalsfield in the result be[]const u32, ignoring that the other positional parameter specifiedstring.
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.