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

Program crashes when using -h to get help #242

Closed
illera88 opened this issue Nov 28, 2022 · 1 comment
Closed

Program crashes when using -h to get help #242

illera88 opened this issue Nov 28, 2022 · 1 comment

Comments

@illera88
Copy link

Program crashes when calling programArgs.parse_args(argc, argv); :

 // Print help message
  friend auto operator<<(std::ostream &stream, const ArgumentParser &parser)
      -> std::ostream & {
    stream.setf(std::ios_base::left);
    stream << "Usage: " << parser.m_parser_path << " [options] ";
    for (const auto &argument : parser.m_positional_arguments) {
      stream << argument.m_names.front() << " "; // Crashes here
    }

0x00007ff6f1872590 L"\"front() called on empty vector\""

void argsHandling(int argc, char** argv) {
    programArgs = argparse::ArgumentParser("program.exe");

    programArgs.add_description("bla bla bla lba");
    programArgs.add_epilog("bla bla bla sdasdsdasdas");

    programArgs.add_argument("--verbose")
        .help("increase output verbosity")
        .default_value(false)
        .implicit_value(true);

    programArgs.add_argument("--json-print")
        .help("print a JSON structure")
        .default_value(false)
        .implicit_value(true);

    programArgs.add_argument("--json-file")
        .help("create a JSON file")
        .default_value(std::string{ "file.json" });

    programArgs.add_argument("--something-path")
        .help("tell program for a path");

    try {
        programArgs.parse_args(argc, argv);

    }
    catch (const std::runtime_error& err) {
        std::cerr << err.what() << std::endl;
        std::cerr << programArgs;
        std::exit(1);
    }
}
@p-ranav
Copy link
Owner

p-ranav commented Oct 27, 2023

Appears to be fixed by #292

@p-ranav p-ranav closed this as completed Oct 27, 2023
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

No branches or pull requests

2 participants