{"id":15047812,"url":"https://github.com/607011/getopt-cpp","last_synced_at":"2026-02-19T18:05:21.012Z","repository":{"id":160468785,"uuid":"635352240","full_name":"607011/getopt-cpp","owner":"607011","description":"A sleek and slender C++'ish alternative to getopt and getopt_long","archived":false,"fork":false,"pushed_at":"2024-06-21T07:52:09.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T13:46:26.924Z","etag":null,"topics":["command-line","cplusplus","cplusplus-11","getopt","getopt-long","parsing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/607011.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-02T14:06:50.000Z","updated_at":"2024-06-21T07:52:12.000Z","dependencies_parsed_at":"2023-12-21T12:12:15.160Z","dependency_job_id":"b9ac3002-bf38-41e0-bc80-486d87bad55b","html_url":"https://github.com/607011/getopt-cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/607011/getopt-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2Fgetopt-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2Fgetopt-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2Fgetopt-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2Fgetopt-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/607011","download_url":"https://codeload.github.com/607011/getopt-cpp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/607011%2Fgetopt-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29626660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","cplusplus","cplusplus-11","getopt","getopt-long","parsing"],"created_at":"2024-09-24T21:04:56.087Z","updated_at":"2026-02-19T18:05:20.992Z","avatar_url":"https://github.com/607011.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getopt++\n\n**A sleek and slender C++'ish alternative to getopt and getopt_long**\n\nThis library is header-only. Just `#include` [getopt.hpp](https://github.com/607011/getopt-cpp/blob/main/include/getopt.hpp) and you're done.\n\nThe `reg()` method registers a handler for a list of command-line switches. If `argparser` finds one of the switches, it calls the handler with the argument, if the switch requires an argument (`argparser::required_argument`), otherwise it calls the handler with an empty string.\n\nIf `argparser` finds command-line parameters without a switch, these can be queried as so-called positional arguments. Handlers for positionals are registered with the `pos()` method.\n\nUsing `info()` and `help()` you can improve the help output.\n\n## Example\n\n```cpp\n#include \u003ccstddef\u003e\n#include \u003cstring\u003e\n\n// this is the getopt++ specific include directive\n#include \u003cgetopt.hpp\u003e\n\nint main(int argc, char *argv[])\n{\n  // variables modified by command-line switches\n  unsigned long num_threads = 1;\n  int verbosity = 0;\n  std::string input_file;\n  std::string output_file;\n\n  // definition of command-line switches\n  using argparser = argparser::argparser;\n  argparser opt(argc, argv);\n  opt\n    .info(\"getopt++ demo\", argv[0])\n    // register command-line switches that execute\n    // the built-in help display\n    .help({\"-?\", \"--help\"}, \"Display this help\")\n    // register command-line switches that modify\n    // a variable according to the argument given\n    .reg({\"-t\", \"--threads\"},\n         \"NUM_THREADS\", // will be used in help to illustrate the argument\n         argparser::required_argument,\n         \"Set number of threads\", // will be displayed in help\n         [\u0026num_threads](std::string const \u0026arg)\n         {\n            num_threads = std::stoul(arg);\n        })\n    // register command-line switch that doesn't\n    // expect an argument, i.e. to increase the\n    // level of verbosity\n    .reg({\"-v\"},\n         argparser::no_argument,\n         \"Increase verbosity of output\",\n         [\u0026verbosity](std::string const \u0026)\n         {\n            ++verbosity;\n         })\n    // register positional arguments\n    .pos(\"INPUT_FILE\", // will be used in help to illustrate the argument\n         \"Set file to read\", // will be displayed in help\n         [\u0026input_file](std::string const \u0026arg)\n         { input_file = arg; })\n    .pos(\"OUTPUT_FILE\", // will be used in help to illustrate the argument\n         \"Set file to write\", // will be displayed in help\n         [\u0026output_file](std::string const \u0026arg)\n         { output_file = arg; });\n  try\n  {\n    // parse command-line and execute handlers accordingly\n    opt();\n  }\n  // user requested help, help was shown, \n  // everything's fine, so exit smoothly\n  catch (::argparser::help_requested_exception const \u0026)\n  {\n    return EXIT_SUCCESS;\n  }\n  // handle cases where a required argument was not given\n  catch (::argparser::argument_required_exception const \u0026e)\n  {\n    std::cerr \u003c\u003c \"\\u001b[31;1mERROR: \" \u003c\u003c e.what() \u003c\u003c \"\\u001b[0m\\n\";\n    return EXIT_FAILURE;\n  }\n  // handle cases where an unknown switch was given\n  catch (::argparser::unknown_option_exception const \u0026e)\n  {\n    std::cerr \u003c\u003c \"\\u001b[31;1mERROR: \" \u003c\u003c e.what() \u003c\u003c \"\\u001b[0m\\n\";\n    opt.display_help(); \n    return EXIT_FAILURE;\n  }\n  // handle all other exceptions\n  catch (std::exception const \u0026e)\n  {\n    std::cerr \u003c\u003c \"\\u001b[31;1mERROR: \" \u003c\u003c e.what() \u003c\u003c \"\\u001b[0m\\n\";\n    return EXIT_FAILURE;\n  }\n  return EXIT_SUCCESS;\n}\n```\n\n\n## More examples\n\n  - [txtz](https://github.com/607011/txtz/blob/main/src/mapbuilder.cpp)\n  - [sudoku++](https://github.com/607011/sudokuplusplus/blob/main/src/main.cpp)\n  - [hibpdl++](https://github.com/607011/hibpdl/blob/main/src/main.cpp)\n  - [dirb++](https://github.com/607011/dirbplusplus/blob/main/src/main.cpp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F607011%2Fgetopt-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F607011%2Fgetopt-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F607011%2Fgetopt-cpp/lists"}