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

Unexpected behavior when using choices() #307

Closed
justou opened this issue Nov 10, 2023 · 0 comments · Fixed by #310
Closed

Unexpected behavior when using choices() #307

justou opened this issue Nov 10, 2023 · 0 comments · Fixed by #310
Assignees
Labels
bug Something isn't working

Comments

@justou
Copy link

justou commented Nov 10, 2023

For example

#include <iostream>
#include "argparse.hpp"

int main(int argc, char **argv) {
    argparse::ArgumentParser program("test");

    program.add_argument("--input")
            .default_value(std::string{"baz"})
            .choices("foo", "bar", "baz");

    program.add_argument("--value").scan<'i', int>().default_value(0);

    try {
        program.parse_args(argc, argv);
        auto input = program.get("input");
        auto value = program.get<int>("value");
        std::cout << input << std::endl;
        std::cout << value << std::endl;
    }
    catch (const std::exception &err) {
        std::cerr << err.what() << std::endl;
        std::cerr << program;
        std::exit(1);
    }
    return 0;
}

main.exe --value 1 --input foo will give the expected result, but
main.exe --input foo --value 1 will complain: Invalid argument "--value" - allowed options: {foo, bar, baz}
It seems the order of choices() on command line matters.

Environment: Windows 10, MSVC2019, argparse v3.0

@p-ranav p-ranav self-assigned this Nov 10, 2023
@p-ranav p-ranav added the bug Something isn't working label Nov 10, 2023
p-ranav added a commit that referenced this issue Nov 13, 2023
russkel pushed a commit to Greenroom-Robotics/argparse that referenced this issue Dec 11, 2023
russkel pushed a commit to Greenroom-Robotics/argparse that referenced this issue Dec 11, 2023
sethhillbrand pushed a commit to KiCad/kicad-source-mirror that referenced this issue Mar 3, 2024
Otherwise .choices doesn't work properly.
See p-ranav/argparse#307
sethhillbrand pushed a commit to KiCad/kicad-source-mirror that referenced this issue Mar 3, 2024
Otherwise .choices doesn't work properly.
See p-ranav/argparse#307

(cherry picked from commit 991b429)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants