{"id":17206923,"url":"https://github.com/michaelgrupp/minicommander","last_synced_at":"2025-07-08T14:07:37.111Z","repository":{"id":86302539,"uuid":"73136036","full_name":"MichaelGrupp/MiniCommander","owner":"MichaelGrupp","description":"A simple, minimalistic command line parser in 100 lines of C++11 code","archived":false,"fork":false,"pushed_at":"2017-08-01T14:34:51.000Z","size":1086,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T10:43:36.788Z","etag":null,"topics":["cli","command-line-parser","commandline-interface","cpp","cpp11","minimalist"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichaelGrupp.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":"2016-11-08T01:13:36.000Z","updated_at":"2023-03-06T02:38:14.000Z","dependencies_parsed_at":"2023-03-03T18:45:29.826Z","dependency_job_id":null,"html_url":"https://github.com/MichaelGrupp/MiniCommander","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MichaelGrupp/MiniCommander","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelGrupp%2FMiniCommander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelGrupp%2FMiniCommander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelGrupp%2FMiniCommander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelGrupp%2FMiniCommander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelGrupp","download_url":"https://codeload.github.com/MichaelGrupp/MiniCommander/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelGrupp%2FMiniCommander/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264284383,"owners_count":23584675,"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","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":["cli","command-line-parser","commandline-interface","cpp","cpp11","minimalist"],"created_at":"2024-10-15T02:44:17.540Z","updated_at":"2025-07-08T14:07:37.095Z","avatar_url":"https://github.com/MichaelGrupp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MiniCommander \n\nA simple, minimalistic but still powerful command line parser in 100 lines of C++11 code.\n\nThe library is header-only and only depends on the C++11 STL.\n\n***Features***\n* *check if a flag exists*\n* *get single parameter from flags*\n* *get multiple parameters from flags*\n* *organize flags in groups and mark them as required, optional or \"any of\"*\n* *add flags to the groups, and optionally their alternative flag and their description*\n* *automatically check if all flags are valid*\n* *automatically print help/usage messages*\n\n## Platforms\nYou will need a C++ compiler that supports C++11 regex, e.g. Clang \u003e3.6 or GCC \u003e4.9.\nAutomatic [unit tests](https://github.com/MichaelGrupp/MiniCommander/blob/master/test/unit_test.cpp) written with [Google Test](https://github.com/google/googletest) are performed on Linux (compilers: GCC 4.9 \u0026 Clang 3.6), as well as on Windows (compiler: MSVC14). Click the build badges for more details:\n\n[![Build Status](https://travis-ci.org/MichaelGrupp/MiniCommander.svg?branch=master)](https://travis-ci.org/MichaelGrupp/MiniCommander)\n[![Build status](https://ci.appveyor.com/api/projects/status/8ubu1kv85rcmiohv/branch/master?svg=true\u0026passingText=Windows%3A%20build%20passing\u0026failingText=Windows%3A%20build%20failing\u0026pendingText=Windows%3A%20build%20pending)](https://ci.appveyor.com/project/MichaelGrupp/minicommander)\n\n## Installation\nJust drop the header file [MiniCommander.hpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/MiniCommander.hpp) in your project and include it in your program.\n\n## Supported Formats for Arguments\n\nBy default, flags can be named arbitrarily. Single parameters appear after a flag (here: `-d`). Multiple space-separated parameters are also possible (here after `-f`).\n```\n-x -y -z -d param -f param1 param2 param3\n-x -y -z -d=param -f=param1 param2 param3\n```\nBy setting the optional `unixFlags`parameter of the class constructor to `true`, multiple options can be combined if they're defined in single dash format (`-*`):\n```\n-xyz -d param\n-xyzd=param\n-xyzd param\n```\nwhich behaves the same as `-x -y -z -d=param`.\n\n* check existence of a single flag `-x` with `optionExists(\"-x\")`\n* a parameter string can be accessed with `getParameter(\"-d\")` \n* `getMultiParameters(\"-f\")` returns the parameter string vector of a multiple parameter flag\n\nIf parameters were not given, the parameter string returned by `getParameter` (or vector by `getMultiParameters`) is empty.\n\n## Grouping Options with Policies\nThe `checkFlags()` function automatically checks if all required flags were given by the user. Furthermore, automatic help messages can be generated with `printHelpMessage`. \n\nTo use these features, the command line options must be first grouped by their check policy: \n* ***required*** - all options of this group must be given\n* ***optional*** - giving these options is not mandatory\n* ***anyOf*** - at least one option of the group must be given\n\nExample of a required option group:\n```c++\n OptionGroup requiredGroup(Policy::required, \"required options\");\n requiredGroup.addOption(\"-d\", \"first required argument\");\n requiredGroup.addOption(\"-f\", \"other required argument\", \"--flag\");\n```\nNote that an **optional long alternative** `--flag` of the `-f` flag was added. This group can now be added to a *MiniCommander* instance via `addOptionGroup`.\n\n## Example Usage\nThis code example [test.cpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/test/test.cpp) shows how to use all of the command line interface functions offered by MiniCommander:\n\n```c++\n#include \u003ciostream\u003e\n#include \"MiniCommander.hpp\"\n\nusing namespace std;  // just for example\n\nint main(int argc, char *argv[])\n{\n    bool unixFlags = false;  // whether to split single char options, e.g. -xyz into -x -y -z\n    MiniCommander cmd(argc, argv, unixFlags);\n\n    OptionGroup paths(Policy::required, \"required paths\");\n    paths.addOption(\"-d\", \"path to data folder\");\n    paths.addOption(\"-f\", \"paths of one or multiple files (separated by space)\");\n    cmd.addOptionGroup(paths);\n\n    OptionGroup formats(Policy::anyOf, \"formats, choose one of them\");\n    formats.addOption(\"-x\", \"use x format\");\n    formats.addOption(\"-y\", \"use y format\");\n    formats.addOption(\"-z\", \"use z format\");\n    cmd.addOptionGroup(formats);\n\n    OptionGroup optionals(Policy::optional, \"optional parameters\");\n    optionals.addOption(\"-a\", \"activate something\");\n    optionals.addOption(\"--help\", \"show info and usage\");\n    cmd.addOptionGroup(optionals);\n\n    if (!cmd.checkFlags() || cmd.optionExists(\"--help\")) {\n        cmd.printHelpMessage(\"MiniCommander Example\\n\\nUSAGE:\");\n        return EXIT_FAILURE;\n    }\n\n    string dataFolder = cmd.getParameter(\"-d\");\n    vector\u003cstring\u003e filePaths = cmd.getMultiParameters(\"-f\");\n    if (dataFolder.empty() || filePaths.empty()) {\n        cerr \u003c\u003c \"error: please specify required paths\" \u003c\u003c endl;\n        cmd.printHelpMessage();\n        return EXIT_FAILURE;\n    }\n    cout \u003c\u003c \"data folder: \" \u003c\u003c dataFolder \u003c\u003c endl;\n    cout \u003c\u003c \"file paths: \";\n    for (auto\u0026 path : filePaths)\n        cout \u003c\u003c path \u003c\u003c \", \";\n\n    if (cmd.optionExists(\"-x\"))\n        cout \u003c\u003c \"\\nusing x format!\" \u003c\u003c endl;\n    else if (cmd.optionExists(\"-y\"))\n        cout \u003c\u003c \"\\nusing y format!\" \u003c\u003c endl;\n    else if (cmd.optionExists(\"-z\"))\n        cout \u003c\u003c \"\\nusing z format!\" \u003c\u003c endl;\n\n    if (cmd.optionExists(\"-a\"))\n        cout \u003c\u003c \"activating something optional!\" \u003c\u003c endl;\n\n    return EXIT_SUCCESS;\n}\n```\nIf [test.cpp](https://github.com/MichaelGrupp/MiniCommander/blob/master/test/test.cpp) is compiled and called with the wrong parameters: \n\n`./test -d ~/Documents/data -f /Documents/xyz.txt /Documents/abc.psd /Documents/123.bin -a`,\n\n(here, none of the options from the ```formats``` group is given and ```checkFlags()``` fails) we get the following output:\n```\nMiniCommander Example\n\nUSAGE:\n\n[required paths]\n-d\tpath to data folder\n-f\tpaths of one or multiple files (separated by space)\n\n[formats, choose one of them]\n-x\tuse x format\n-y\tuse y format\n-z\tuse z format\n\n[optional parameters]\n--help\tshow info and usage\n-a\tactivate something\n```\n\nWith correct parameters, e.g.: \n\n`./test -x -d ~/Documents/data -f /Documents/xyz.txt /Documents/abc.psd /Documents/123.bin -a`, \n\nwe get:\n```\ndata folder: /Documents/data\nfile paths: /Documents/xyz.txt, /Documents/abc.psd, /Documents/123.bin, \nusing x format!\nactivating something optional!\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelgrupp%2Fminicommander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelgrupp%2Fminicommander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelgrupp%2Fminicommander/lists"}