https://github.com/bitmeal/argv_split
split string of command line arguments to an argv-like array (supports quotes) for C++
https://github.com/bitmeal/argv_split
argument-parser argv argv-parser cli cli-testing command-line-parser
Last synced: 4 months ago
JSON representation
split string of command line arguments to an argv-like array (supports quotes) for C++
- Host: GitHub
- URL: https://github.com/bitmeal/argv_split
- Owner: bitmeal
- Created: 2018-12-28T20:05:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T08:39:24.000Z (almost 2 years ago)
- Last Synced: 2025-04-05T05:11:23.041Z (10 months ago)
- Topics: argument-parser, argv, argv-parser, cli, cli-testing, command-line-parser
- Language: C++
- Homepage:
- Size: 13.7 KB
- Stars: 8
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.com/bitmeal/argv_split)
[ G++-5/6/7 ]
# argv split
Simple parser to split a command line string into its components, like you'll find them in `argv`. Splits on whitespace and keeps quoted parts together. Supports single and double quotes; quotes can be nested (one level, eg: `"foo 'bar'"`) and will not be treated as quotes if escaped by a backslash (`\"` or `\'`).
Tests are in `tests` directory and use CMake-integrated testing; call `make all` and `make test`.
## use
Header only. Include and use as shown. Parameter to the constructor can be omited, but your arguments array will be missing the program name; you can allway specify it explicitly in your arguments string.
```C++
argv_parser parser("programm_name");
parser.parse("-p \"my flag param\" --switch='switch value'");
const char** my_argv = parser.argv();
```
## tests
Uses CMake-integrated testing: Tests are configured in `tests/CMakeLists.txt`, using the provided function `add_cmdline_test( "" )`. This will generate a test-units C++ code, including the given string of arguments. On execution, the arguments given on the command line and the arguments extracted from the given string are compared - test passes if they match.