An open API service indexing awesome lists of open source software.

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.

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```.