msvc 2015, msvc 2017 | gcc 6, gcc 7, clang 3.6, clang 5.0 | test coverage |
---|---|---|
C++ command line parser toolkit for kids of all ages.
- GNU style command lines (-o, --output=FILE, etc.)
- parses directly to any supplied (or implicitly created) variable that is:
- default constructible
- copyable
- assignable from string, has an istream extraction operator, or has a specialization of Cli::fromString<T>()
- help generation
- option definitions can be scattered across multiple files
- git style subcommands
- response files (requires
<filesystem>
support) - works whether exceptions and RTTI are enabled or disabled
Check out the wiki, you'll be glad you did! Contains thorough documentation with many examples. Or click here if you prefer it all on a single page.
All you need is:
- libs/dimcli/cli.h
- libs/dimcli/cli.cpp
Using vcpkg on Windows
- vcpkg install dimcli
Get the latest snapshot: dimcli 4.1.0
Build it (this example uses Visual C++ 2015 to install a 64-bit build to c:\dimcli on a windows machine):
- cmake .. -DCMAKE_INSTALL_PREFIX=c:\dimcli -G "Visual Studio 14 2015 Win64"
- cmake --build .
- ctest -C Debug
- cmake --build . --target install
- Prerequisites
- install cmake >= 3.6
- install Visual Studio 2015
- include the "Github Extension for Visual Studio" (if you care)
- include git
- Make the library
- git clone https://github.com/gknowles/dimcli.git
- cd dimcli
- md build & cd build
- cmake .. -G "Visual Studio 14 2015 Win64"
- cmake . --build
- Test
- ctest -C Debug
- Visual Studio 2015
- open dimcli\dimcli.sln (not the one in dimcli\build\dimcli.sln) for github integration to work
Why not a single header file?
- On large projects with many binaries (tests, utilities, etc) it's good for compile times to move as much stuff out of the headers as you easily can.
- Inflicting <Windows.h> (and to a much lesser extent <termios.h> & <unistd.h>) on all clients seems a bridge too far.
Sources of inspiration:
- LLVM's CommandLine module
- click - Python command line interface creation kit
- My own bad experiences
Things that were harder than expected:
- parsing command lines with bash style quoting
- response files - because of the need to transcode UTF-16 on windows
- password prompting - there's no standard way to disable console echo :(
- build system - you can do a lot with cmake, but it's not always easy
Other interesting c++ command line parsers:
- program_options - from boost
- gflags - from google
- tclap - header only
- args - single header
- cxxopts - single header