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

Missing argument doesn't throw exception #118

Closed
ThomasKrenn opened this issue Jun 15, 2023 · 1 comment
Closed

Missing argument doesn't throw exception #118

ThomasKrenn opened this issue Jun 15, 2023 · 1 comment
Assignees

Comments

@ThomasKrenn
Copy link

Hello
shouldn't missing arguments throw an exception?

Below is a very simple test case that fails to throw an exception.

TEST_CASE("Missing argument throw exception", "[args]")
{
    args::ArgumentParser parser("A test program.", "More text");
    args::Positional<std::string> input(parser, "input", "Compulsory input");
    REQUIRE_THROWS_AS(parser.ParseArgs(std::vector<std::string>{}), args::ParseError);
}

Best regards
Thomas

@Taywee
Copy link
Owner

Taywee commented Jun 16, 2023

Nope. That variable gets initialized via default construction, and you can check whether it was present using the boolean operator, if (input), as shown here.

If you want a required argument, you can mark it as such.

@Taywee Taywee closed this as completed Jun 16, 2023
@Taywee Taywee self-assigned this Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants