Skip to content

Lightweight commandline parser single-header library in C++

License

Notifications You must be signed in to change notification settings

max8447/CmdLineParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CmdLineParser

Lightweight commandline parser single-header library in C++

How to use

  1. Define DEFINE_CMDLINE_FIELDS macro with the corresponding fields for your command line arguments:
#define DEFINE_CMDLINE_FIELDS(Define)           \
Define(int, arg1, "-d", true);					\
Define(bool, arg2, "-e", false);				\
Define(char*, arg3, "-p", true);				\
Define(float, arg4, "-f", true);

Parameters:
Type of the argument
Name of the argument (the name is arbitrary)
The flag for which is searched
Whether or not to use the next argument for the value

  1. Call the DEFINE_CMDLINE macro:
DEFINE_CMDLINE();
  1. Define command line variable of type CmdLine:
CmdLine CommandLine;
  1. Call the ParseCmdLine function:
bool bSuccess = ParseCmdLine(argc, argv, &CommandLine, sizeof(CmdLine), &Translator, sizeof(Translator);

Parameters:
Number of arguments (passed to main by argc)
Pointer to arguments (passed to main by argv)
Pointer to CmdLine variable we just created
Size of CmdLine
Pointer to Translator (variable defined by the DEFINE_CMDLINE macro)
Size of Translator

Return value:
true on success, false on failure (failures only happen when a commandline arg is flagged to use the next arg as the value but there is no next arg).

See Example.cpp for a ready-to-use solution.

Any contributions are welcome.

About

Lightweight commandline parser single-header library in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages