https://github.com/paulanerus/argparser
ArgParser - Simple, single header-only C++17 library for command parsing
https://github.com/paulanerus/argparser
argument-parser argument-parsing cli cli-args command-line-parser commands cpp cpp17 cpp20 header-only header-only-library parser parsing-library
Last synced: 4 months ago
JSON representation
ArgParser - Simple, single header-only C++17 library for command parsing
- Host: GitHub
- URL: https://github.com/paulanerus/argparser
- Owner: Paulanerus
- License: mit
- Created: 2024-02-27T18:24:59.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-22T08:24:21.000Z (over 1 year ago)
- Last Synced: 2025-05-20T17:15:35.033Z (10 months ago)
- Topics: argument-parser, argument-parsing, cli, cli-args, command-line-parser, commands, cpp, cpp17, cpp20, header-only, header-only-library, parser, parsing-library
- Language: C++
- Homepage: https://paulee.dev/argparser
- Size: 80.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ArgParser
ArgParser is a simple, single header-only C++17 library to parse command like input. Similar in functionality to tools like [cargo](https://doc.rust-lang.org/stable/cargo/), the Rust package manager. It started as a testing project and after some development I thought that someone could use this as well.
This library was tested on Windows (MSCV) and GNU/Linux (GCC, Clang), with additional checking on GNU/Linux with [Valgrind](https://valgrind.org/)
## Examples
Example 1:
```c++
#include "arg_parser.hpp"
int main(int argc, char* argv[])
{
psap::ArgParser parser{
psap::ParserConf{"project_name", 4, true, true, psap::ValueStyle::Both, psap::UnknownOptionPolicy::ReportRemove}};
auto HELP_ACTION =
[](const psap::ArgParser &parser, const psap::Command &cmd)
{
parser(parser[0]); // Print info text of remaining args
}
parser.command("help", "h")
.help("Shows help.")
.action(HELP_ACTION);
//More commands to come
parser.parse(argv, argc);
}
```
Output:
```
Usage: project_name [Command] [Options]
Commands:
help, h Shows help.
See 'project_name help ' for more information on a specific command.
```
Example 2:
```c++
psap::ArgParser parser{
psap::ParserConf{"project_name", 4, true, true, psap::ValueStyle::Both, psap::UnknownOptionPolicy::ReportRemove}};
auto RUN_ACTION =
[](const psap::ArgParser &parser, const psap::Command &cmd)
{
//Run action...
}
parser.command("run", "r")
.help("Runs something.")
.option(psap::make_value("--target", "-t", "Select a Target."))
.option(psap::make_flag("--debug", "-d", "Runs in debug."))
.action(RUN_ACTION);
//More commands to come
parser.parse(argv, argc);
```
## Documentation
Documentation can be found in the [wiki](https://github.com/Paulanerus/ArgParser/wiki) pages.
## Dependencies
ArgParser has no other dependencies.
## Support
If you encounter any issues or have any questions about this project, don't hesitate to reach out to me. You can [open an issue](https://github.com/Paulanerus/ArgParser/issues) on GitHub.