# cpp-cmdline **Repository Path**: mutouyun/cpp-cmdline ## Basic Information - **Project Name**: cpp-cmdline - **Description**: An easy way to analyse command line in C++. - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2018-03-24 - **Last Updated**: 2024-06-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # An easy way to analyse command line in C++. [![Build Status](https://travis-ci.org/mutouyun/cpp-cmdline.svg?branch=master)](https://travis-ci.org/mutouyun/cpp-cmdline) [![Build status](https://ci.appveyor.com/api/projects/status/e8ci4mtpyb1gy936/branch/master?svg=true)](https://ci.appveyor.com/project/mutouyun/cpp-cmdline) This is a simple library for C++ to analyse command line. This library only depends on STL. # Compiler Support - MSVC-2015 - g++-4.9.2(-std=c++1y) - clang-3.4(-std=c++1y) # License Codes covered by the MIT License. # Tutorial For using it, you only need to include cmdline.hpp. Simple usage: ```cpp #include "cmdline.hpp" int main(int argc, char* argv[]) { cmdline::parser a; a.push({ { "-h", // short name "--help", // long name "Print usage.", // description false, // is necessary or not "", // default value [&a](auto&) { a.print_usage(); } // handle for doing something }, { "-t", "--test", "You must use this option.", true, "", [](auto&) { /*Do Nothing.*/ } }, { "-o", "--output", "Print text.", true, "Hello World!", [](auto& str) { std::cout << str << std::endl; } } }); a.exec(argc, argv); return 0; } ``` And there are the execution results: ``` $ ./ut Usage: ut --test --output=Hello World! [OPTIONS]... Options: -t, --test You must use this option. -o, --output Print text.[=Hello World!] -h, --help Print usage. ``` ``` $ ./ut -h Usage: ut --test --output=Hello World! [OPTIONS]... Options: -t, --test You must use this option. -o, --output Print text.[=Hello World!] -h, --help Print usage. ``` ``` $ ./ut -o=fdagdag Usage: ut --test --output=Hello World! [OPTIONS]... Options: -t, --test You must use this option. -o, --output Print text.[=Hello World!] -h, --help Print usage. ``` ``` $ ./ut -o=fdagdag -t fdagdag ``` ``` $ ./ut -o -t Hello World! ```