p-ranav / argparse

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

m_is_used not updated in parent of subcommand #314

Open CorrM opened 10 months ago

CorrM commented 10 months ago
argparse::ArgumentParser program("test", "0.0.1");
    argparse::ArgumentParser genParser("gen", "0.0.1", argparse::default_arguments::none);
    genParser.add_argument("-c", "--config")
            .help("Configration file path.")
            .metavar("CONFIG")
            .required();

    // Cpp
    argparse::ArgumentParser cppCommand("cpp");
    cppCommand.add_description("Generate C++ language SDK.");
    cppCommand.add_parents(genParser);

    cppCommand.add_argument("--namespace")
            .help("Set the C++ namespace for the generated SDK.")
            .metavar("NAMESPACE")
            .action([&properties](const std::string& value){ properties.emplace_back("namespace", value); });

    program.add_subparser(cppCommand);

    // CSharp
    argparse::ArgumentParser csharpCommand("csharp");
    csharpCommand.add_description("Generate C# language SDK.");
    csharpCommand.add_parents(genParser);

    program.add_subparser(csharpCommand);

    // Python
    argparse::ArgumentParser pythonCommand("python");
    pythonCommand.add_description("Generate Python language SDK.");
    pythonCommand.add_parents(genParser);

    program.add_subparser(pythonCommand);
std::string configPath = program.get("-c"); // No such argument: -c
std::string configPath = genParser.get("-c"); // Nothing parsed, no arguments are available.
std::string configPath = cppCommand.get("-c"); // Work

when i debug, genParser have the the argument but argument field are not updated. as workaround i could do some condition around is_subcommand_used but i think its not the correct way to do it.