https://github.com/sebastianbach/cmdl-args
A tool that generates C++ code that parses command line arguments.
https://github.com/sebastianbach/cmdl-args
code-generation command-line-arguments-parser cpp cpp20
Last synced: 8 months ago
JSON representation
A tool that generates C++ code that parses command line arguments.
- Host: GitHub
- URL: https://github.com/sebastianbach/cmdl-args
- Owner: SebastianBach
- License: mit
- Created: 2023-02-27T18:53:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-28T18:53:36.000Z (over 2 years ago)
- Last Synced: 2025-01-08T13:51:58.815Z (9 months ago)
- Topics: code-generation, command-line-arguments-parser, cpp, cpp20
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A tool that generates specific C++ code that parses command line arguments based on a description of the desired arguments.
```
#include
#include "parser.h"int main(int argc, char* argv[])
{
const auto app_arguments = args::parse(argc, argv);if (app_arguments.help) {
args::print_help();
return 0;
}if (!app_arguments.input.has_value()) {
std::cout << "Missing input argument.";
return -1;
}const auto input = app_arguments.input.value();
// handle input...
return 0;
}```
The generated code requires C++ 17 (using ```std::optional```).
# Build
```
mkdir build
cd build
cmake ..
cmake --build . --config Release
ctest -C Release -VV
```# Usage
## Arguments
Basic arguments are:
- --i: Input File path.
- --o: Output folder path.
- --header: Output Header File
- --cpp: Output Source File.A typical call would be
```
cmdl-args.exe --i C:\my_project\args.txt --o C:\my_project\code --header parser.h --cpp parser.cpp
```Options to configure the resulting code are:
- --pragma: Use pragma as include guard.
- --space: Namespace.
- --hyphen: Characters preceding the arguments.
- --tab: Tab size in spaces.
- --comments: Enable comments.
- --date: Include creation date.
- --print: Include ```print_help()``` function.
- --values: Include ```print_values()``` function.Further options are:
- --help: Print help text.
- --version: Print version.
- --v: Verbose output.## Input File
An input files is a simple text file describing the desired command line arguments. The format is
```
::
```Types are
- **f**: Flag, is either set or not.
- **s**: String.
- **d**: Double value.
- **i**: Integer value.As an example:
```
help:f:Print help text
i:s:Input File
o:s:Output Folder
```See ```src/app/args.txt```.