Skip to content

A tool that generates C++ code that parses command line arguments.

License

Notifications You must be signed in to change notification settings

SebastianBach/cmdl-args

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A tool that generates specific C++ code that parses command line arguments based on a description of the desired arguments.

#include <iostream>
#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

<ARG>:<TYPE>:<DESCRIPTION>

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.

About

A tool that generates C++ code that parses command line arguments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published