{"id":19708764,"url":"https://github.com/bendudson/argopts","last_synced_at":"2025-08-08T04:20:07.730Z","repository":{"id":137712271,"uuid":"102536195","full_name":"bendudson/argopts","owner":"bendudson","description":"A simple command-line parser for C++11","archived":false,"fork":false,"pushed_at":"2017-10-02T09:15:05.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T18:31:06.892Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/bendudson.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":"2017-09-05T22:36:16.000Z","updated_at":"2021-04-04T02:59:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"351187e0-aefb-4cbe-a8de-bd0e215987be","html_url":"https://github.com/bendudson/argopts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bendudson/argopts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendudson%2Fargopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendudson%2Fargopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendudson%2Fargopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendudson%2Fargopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bendudson","download_url":"https://codeload.github.com/bendudson/argopts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendudson%2Fargopts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269362630,"owners_count":24404586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-11T21:44:49.040Z","updated_at":"2025-08-08T04:20:07.648Z","avatar_url":"https://github.com/bendudson.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"ArgOpts\n=======\n\nA simple command line option parser for C++11.\n\nFeatures\n--------\n\n* Short options like \"-h\", \"-v\", which can be combined so that \"-hvv\" is equivalent to \"-h -v -v\".\n* Long options like \"--help\", \"--verbose\".\n* Values set using \"--output=somefile.txt\" or \"--output somefile.txt\" syntax.\n* For short options \"-ab=value\" or \"-ab value\" is equivalent to \"-a=value -b=value\".\n* Arguments not starting with '-' are ignored, and parsing stops when '--' is found.\n* Stringstream for type conversion, allowing simple extension for custom types.\n* Error handling using exceptions.\n* Unit testing with Google Test (https://github.com/google/googletest)\n* All code in a single header file.\n* Released under MIT license.\n\nExample\n-------\n\n```C++\n#include \u003ciostream\u003e\n#include \"argopts.hxx\"\n\nint main(int argc, char **argv) {\n\n  // Specify the arguments to recognise (this is optional)\n  // Format is:\n  //   { Short form (single character), long form, help message }\n  ArgOpts::Parser args = { {'h', \"help\", \"print this help message\"},\n                           {'f', \"file\", \"[FILE] file name\"},\n                           {'n', \"number\", \"[NUMBER] An important integer\"}};\n\n  std::string filename;\n  int num = 0;\n  \n  for (auto \u0026opt : args.parse(argc, argv)) {\n    switch (opt.shortopt) {\n    case 'h': {  // This matches both -h and --help\n      std::cout \u003c\u003c \"Usage:\\n\" \u003c\u003c argv[0] \u003c\u003c \" [options]\\n\";\n      std::cout \u003c\u003c \"Options:\\n\" \u003c\u003c args.printOptions() \u003c\u003c \"\\n\";\n      return 0;\n    }\n    case 'f': {  // Matches -f and --file\n      filename = opt.arg;\n      std::cout \u003c\u003c \"Using file: '\" \u003c\u003c filename \u003c\u003c \"'\\n\";\n      break;\n    }\n    case 'n': {  // Matches -n and --number\n      num = opt.arg; // Expect an int as the next argument\n      std::cout \u003c\u003c \"Got number: \" \u003c\u003c num \u003c\u003c \"\\n\";\n      break;\n    }\n    default: {\n      std::cerr \u003c\u003c \"Unrecognised option \" \u003c\u003c opt.usage() \u003c\u003c \"\\n\";\n      return 1;\n    }\n    }\n\n    // Program does useful things...\n\n    return 0;\n  }\n```\n\nThis example throws an exception if an option is missing, so\nan error is printed e.g. a missing argument after \"-n\":\n\n    terminate called after throwing an instance of 'std::invalid_argument'\n    what():  Missing argument, expected type int\n    usage: -n, --number\t\t[NUMBER] An important integer\n\nor if a value cannot be parsed correctly e.g. putting \"-n something\" on the\ncommand-line results in:\n\n    terminate called after throwing an instance of 'std::invalid_argument'\n    what():  Invalid argument: expected type int but got 'something'\n    usage: -n, --number\t\t[NUMBER] An important integer\n\nSimilar projects\n----------------\n\nCommand-line parsing is a pretty common itch, which has been scratched many times.\nFor example:\n\n* optionparser http://optionparser.sourceforge.net\n* cxxopts https://github.com/jarro2783/cxxopts\n* Argh! https://github.com/adishavit/argh\n* docopt https://github.com/docopt/docopt.cpp\n* Clara https://github.com/philsquared/Clara\n* TCLAP http://tclap.sourceforge.net/\n* args https://github.com/Taywee/args\n* GetPot http://getpot.sourceforge.net/\n* gflags https://gflags.github.io/gflags/\n\nOf these, ArgOpts is probably closest to Argh! in that it is quite relaxed about\naccepting input, ignores things it doesn't recognise, and tests type\nconversion as needed.\n\nMIT licence (OSI)\n-----------------\n\nCopyright (c) 2017 Ben Dudson \u003cbenjamin.dudson@york.ac.uk\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendudson%2Fargopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbendudson%2Fargopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendudson%2Fargopts/lists"}