Skip to content

Improved clarity in RequiredError - #1029

Merged
henryiii merged 2 commits into
CLIUtils:mainfrom
sifferman:clearer-RequiredError
Apr 7, 2024
Merged

henryiii merged 2 commits into
CLIUtils:mainfrom
sifferman:clearer-RequiredError

Conversation

@sifferman

Copy link
Copy Markdown
Contributor

Hello. Thank you for this tool.

I found a few small typos in the RequiredError class.

This is an error message I received:

Requires at most 2 options be used and 3were given from [filename,--get-size,--get-size2]

This PR changes the error message to

Requires at most 2 options be used but 3 were given from [filename,--get-size,--get-size2]

Happy to make changes as needed!

Source

    std::string filename;
    bool get_size = false;

    CLI::App app{"Program to read a file specified as command-line argument"};

    app.add_option("filename", filename, "File to read")->required();
    app.add_flag("--get-size", get_size, "Print the size of the file");
    app.add_flag("--get-size2", get_size, "Print the size of the file2");

    app.require_option(1, 2); // Enforce only one flag can be input

    CLI11_PARSE(app, argc, argv);

Further Idea

Also, another idea I had was to remove required options from this error message. In this example, "filename" is required, so a better error message would be

Requires at most 1 options be used but 2 were given from [--get-size,--get-size2]

I'm happy to look into this if you feel it would be valuable

@henryiii

henryiii commented Apr 7, 2024

Copy link
Copy Markdown
Collaborator

Sure, sounds like a reasonable further cleanup; thanks for this!

@henryiii
henryiii merged commit 8bf340d into CLIUtils:main Apr 7, 2024
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

Successfully merging this pull request may close these issues.

2 participants