msvc 2015, msvc 2017, msvc 2019 gcc 7, gcc 8, gcc 9, clang 6 |
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::OptBase::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
- distributed under the Boost Software License, Version 1.0.
Check out the documentation, you'll be glad you did! Thorough with many examples.
All you need is:
- libs/dimcli/cli.h
- libs/dimcli/cli.cpp
Using vcpkg
- vcpkg install dimcli
Get the latest snapshot: dimcli 5.0.2
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
- 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: