cxxopts: options.help({}) doesn't show positional arguments sometimes

Code sample:

int main(int argc, char *argv[]) {
    try {
        cxxopts::Options options(argv[0], "Sample");
        options.positional_help("<Extra args>");
        
        options.add_options()
        ("s,set", "Set whatever.", cxxopts::value<std::vector<std::string>>())
        ("h,help", "Print help and exit.")
        ;
       
        options.parse(argc, argv);
        options.parse_positional({"file", "remove-label", "set-label"});
       
        // help
        if (options.count("help")) {
        cout << options.help({""}) << std::endl;
        exit(0);
        }
    } catch (const cxxopts::OptionException& e) {
        cout << "error parsing options: " << e.what() << std::endl;
        exit(-1);
        }
    return 0;
}

Expected: Show the “set” option in the help. Actual: Show only “help” option.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 20 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry for the inconvenience.

can you try this code please:

int main(int argc, char *argv[]) {
  try {
    cxxopts::Options options(argv[0], "Sample");
    options.positional_help("<Extra args>");

    options.add_options()
        ("s,set-label", "Set a  ", cxxopts::value<std::vector<std::string>>())
        ("h,help", "Print help and exit.")
        ;

    options.parse_positional("set-label");
    options.parse(argc, argv);

    // help
    if (options.count("help")){
      cout << options.help({""}) << std::endl;
      exit(0);
    }
  } catch (const cxxopts::OptionException& e) {
    cout << "error parsing options: " << e.what() << std::endl;
    exit(-1);
  }

  return 0;
}

It’s happen only with an argument with the name “set-label”. Thanks,