p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.59k stars 244 forks source link

choices() method not working properly #324

Closed PeppeRu96 closed 5 months ago

PeppeRu96 commented 7 months ago

If you have two arguments (string), one with a choices() clause and the other without it, parsing fails saying that the argument without .choices() has invalid arguments and that the argument must be chosen from the options of the other argument (the one with .choises()).. Code: ` // Argument parser argparse::ArgumentParser parser("NPULookup");

parser.add_argument("--model_dir")
        .required();

parser.add_argument("--strategy")
        .choices("asymmetric", "gather_reduce")
        .required();

try {
    parser.parse_args(argc, argv);
}
catch (const std::exception& err) {
    std::cerr << err.what() << std::endl;
    std::cerr << parser;
    std::exit(1);
}` 

Invokation: ./npu_lookup --strategy=gather_reduce --model_dir=./models/baseline_table/trows-100_seqlen-1_cores-32_bs-512/ Output: **Invalid argument "--model_dir" - allowed options: {asymmetric, gather_reduce} Usage: NPULookup [--help] [--version] --model_dir VAR --strategy VAR

Optional arguments: -h, --help shows help message and exits -v, --version prints version information and exits --model_dir [required] --strategy [required]**

rouault commented 5 months ago

I believe this can be closed. It no longers occurs with the current version:

$ ./mytest --strategy=gather_reduce --model_dir=./models/baseline_table/trows-100_seqlen-1_cores-32_bs-512/ && echo $?
0
PeppeRu96 commented 5 months ago

Solved with the current version.

nmoreaud commented 3 months ago

@p-ranav @rouault I have the same error with version 3.0, I think that it is not released yet (seems to work with the latest dev version).

subcommand.add_argument("-v", "--verbose")
    .help("verbose output")
    .flag();

subcommand.add_argument("--output-format")
            .default_value(string("png"))
            .choices("png", "jpg")
            .nargs(1)
            .help("format of generated file [png|jpg]");
my_program subcommand --output-format png test
Invalid argument "test" - allowed options: {png, jpg}