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

Allow short commands without long options #115

Open
michidk opened this issue Dec 27, 2023 · 1 comment
Open

Allow short commands without long options #115

michidk opened this issue Dec 27, 2023 · 1 comment

Comments

@michidk
Copy link

michidk commented Dec 27, 2023

The following code:

    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(gpa.deinit() == .ok);

    var alloc = gpa.allocator();

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

    var diag = clap.Diagnostic{};
    var res = clap.parse(clap.Help, &params, clap.parsers.default, .{
        .diagnostic = &diag,
        .allocator = alloc,
    }) catch |err| {
        diag.report(io.getStdErr().writer(), err) catch {};
        return err;
    };
    defer res.deinit();

Errors out while building:

vscode ➜ /workspaces/my-project (main) $ zig build run -- -h
zig build-exe my-project Debug native: error: the following command terminated unexpectedly:
/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 failure
   └─ install transitive failure
      └─ install my-project transitive failure
         └─ zig build-exe my-project Debug native (reused)
error: the following build command failed with exit code 1:
/workspaces/my-project/zig-cache/o/0eb5808b79de382229c649195106f6bc/build /usr/local/lib/zig/zig /workspaces/my-project /workspaces/my-project/zig-cache /home/vscode/.cache/zig run -- -h

It works fine once I change the params to:

    const params = comptime clap.parseParamsComptime(
        \\-h,--help                Display this help.
        \\<str>                     The host to connect to.
        \\
    );
@Hejsil
Copy link
Owner

Hejsil commented Dec 28, 2023

Hmm. I don't see a compiler error. I suspect a compiler crash. Is this the same as #84 ?

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