/MdtCommandLineParser

Library to help to create a command-line parser in a C++ application

Primary LanguageC++GNU Lesser General Public License v3.0LGPL-3.0

MdtCommandLineParser

Description

Library to help to create a command-line parser in a C++ application.

Key points:

  • Parser based on a C++ definition
  • Support for sub-command (1 level)
  • Support for Bash TAB completion (generated from the definition)

C++ does not offer native command-line arguments parsing built-in.

A portable solution is to use QCommandLineParser, which does the job well, but has some missing features:

  • No built-in support for the concept of sub-command
  • Mixing the parser definition into the parser make the API a bit confusing
  • No support for Bash TAB completion built-in

Usage

A example of code is available in the API documentaion.

CMake project description

Update your CMakeLists.txt to use the required libraries:

cmake_minimum_required(VERSION 3.15)
project(MyApp)

find_package(Threads REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core)
find_package(Mdt0 REQUIRED COMPONENTS CommandLineParser )

add_executable(myApp myApp.cpp)
target_link_libraries(myApp Mdt0::CommandLineParser)

Project using Conan

If you use Conan, add MdtCommandLineParser as requirement in your conanfile.txt:

[requires]
MdtCommandLineParser/x.y.z@scandyna/testing

[generators]
CMakeDeps
CMakeToolchain
VirtualBuildEnv

Add the remote:

conan remote add gitlab https://gitlab.com/api/v4/projects/25668674/packages/conan

Install the dependencies:

mkdir build && cd build
conan install .. --profile your_profile -s build_type=Debug

If you don't use the native compiler, and your Conan profile defines one (or it defines some other environments), bring the required environment to the current shell:

source conanbuild.sh

On Windows:

.\conanbuild.bat

Configure your project:

cmake -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug ..

Maybe adjust some settings:

cmake-gui .

Build:

cmake --build . --config Debug

To run the tests:

ctest --output-on-failure -C Debug

If applicable, restore the previous shell environment:

source deactivate_conanbuild.sh

On Windows:

.\deactivate_conanbuild.bat

For a list of available packages, and also some other details, see Conan packages README.

For more details about conan install and build options, see the BUILD documentation.

Manual install

It is also possible to install MdtCommandLineParser locally. See INSTALL.

Then, configure your project and specify the path of the installed MdtCommandLineParser and the dependencies:

cmake -DCMAKE_PREFIX_PATH="/some/path/MdtCommandLineParser;/some/path/MdtCMakeConfig;/some/path/MdtCMakeModules;/some/path/qt/Qt5/5.15.2/gcc_64" ..

Work on MdtCommandLineParser

Build

See BUILD.

Create Conan package

See README in the conan packaging folder.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.