zeule / dimcli

C++ Command Line Parser Toolkit

Home Page:https://gknowles.github.io/dimcli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dimcli

msvc 2015, msvc 2017, msvc 2019
gcc 7, gcc 8, gcc 9, clang 6
test coverage
AppVeyor Status codecov

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.

Documentation

Check out the documentation, you'll be glad you did! Thorough with many examples.

Include in Your Project

Copy source directly into your project

All you need is:

  • libs/dimcli/cli.h
  • libs/dimcli/cli.cpp

Using vcpkg

  • vcpkg install dimcli

Using cmake

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

Working on the dimcli Project

  • Prerequisites
    • install cmake >= 3.6
    • install Visual Studio >= 2015
      • include the "Github Extension for Visual Studio" (if you care)
      • include git
  • Make the library
  • Test
    • ctest -C Debug
  • Visual Studio
    • open dimcli\dimcli.sln (not the one in dimcli\build\dimcli.sln) for github integration to work

Random Thoughts

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:

About

C++ Command Line Parser Toolkit

https://gknowles.github.io/dimcli/

License:Boost Software License 1.0


Languages

Language:C++ 92.8%Language:CMake 7.2%Language:Batchfile 0.1%