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

CommandArgumentNotProvided error when argRequired is set to false #4

Closed
musaprg opened this issue Sep 4, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working error handler Issues related to error.zig

Comments

@musaprg
Copy link

musaprg commented Sep 4, 2022

Hi, I want to show a help message when no arguments are passed or the "-h" flag is passed.
I set the argRequired option to false, but it returned an error when no arguments passed.

env

  • yazap v0.2.0
  • Zig v0.9.1

Current behavior

...
var parser = Command.new(allocator, "sample");
defer parser.deinit();

var subcmd = Command.new(allocator, "init");
try subcmd.addArg(flag.boolean("help", 'h'));
try subcmd.takesSingleValue("FOOBAR");
subcmd.argRequired(false);
try parser.addSubcommand(subcmd);

var args = try parser.parseProcess();
defer args.deinit();
...
error(zigarg): The command 'sample' requires a value but none is provided

error: CommandArgumentNotProvided
/src/lib/zig-arg/src/parser/Parser.zig:415:13: 0x25401b in .zig-arg.parser.Parser.parseSubCommand (sample)
            return self.err_ctx.err;
            ^
/src/lib/zig-arg/src/parser/Parser.zig:147:28: 0x24ee37 in .zig-arg.parser.Parser.parse (sample
            const subcmd = try self.parseSubCommand(token.value);
                           ^
/src/lib/zig-arg/src/Command.zig:168:9: 0x248e9b in .zig-arg.Command.parseFrom (sample)
        return e;
        ^
/src/lib/zig-arg/src/Command.zig:160:5: 0x243703 in .zig-arg.Command.parseProcess (sample)
    return self.parseFrom(self.process_args.?[1..]);
    ^
/src/src/main.zig:345:16: 0x23cb37 in main (sample)
    var args = try parser.parseProcess();

Expected behavior

no error when "argRequired" is false.

I guess the issue comes from around here. It should take care of this situation and suppress the error when "argRequired" is false.

https://github.com/PrajwalCH/yazap/blob/4153a51dea5f1c3771a85fbff1b9b330988a73db/src/parser/Parser.zig#L413-L415

@prajwalch prajwalch added bug Something isn't working error handler Issues related to error.zig labels Sep 4, 2022
@prajwalch
Copy link
Owner

Error message also seems incorrect.

Let me fix this two and push the patch.

@prajwalch prajwalch changed the title CommandArgumentNotProvided error when argRequired is set to false CommandArgumentNotProvided error when argRequired is set to false Sep 4, 2022
prajwalch pushed a commit that referenced this issue Sep 4, 2022
prajwalch pushed a commit that referenced this issue Sep 27, 2022
I mistakenly mention the #4 issue instead of #6 therefore this commit is
for fixing

Signed-off-by: PrajwalCH <prajjwal2058@gmail.com>
@prajwalch prajwalch self-assigned this Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working error handler Issues related to error.zig
Projects
None yet
Development

No branches or pull requests

2 participants