|
|
7 luni în urmă | |
|---|---|---|
| .. | ||
| cmake | 7 luni în urmă | |
| docs | 7 luni în urmă | |
| examples | 7 luni în urmă | |
| include | 7 luni în urmă | |
| src | 7 luni în urmă | |
| tests | 7 luni în urmă | |
| .clang-format | 7 luni în urmă | |
| .gitignore | 7 luni în urmă | |
| CMakeLists.txt | 7 luni în urmă | |
| LICENSE | 7 luni în urmă | |
| README.md | 7 luni în urmă | |
| syscmdlineConfig.cmake.in | 7 luni în urmă | |
C++ Advanced Command Line Parser.
Inspired by Qt QCommandLineParser and C# System.CommandLine.
To be in line with the principle of "don't learn anything new if you don't need to", on the one hand, syscmdline contains as many common features as possible, on the other hand, it's simple enough to be easy to understand.
Therefore, the project is designed to be configurable, but it's not intended to be as complex as a framework.
A simple mv command:
#include <iostream>
#include <syscmdline/parser.h>
namespace SCL = SysCmdLine;
int main(int argc, char *argv[]) {
SCL::Command cmd("mv", "move files to directory");
cmd.addArguments({
SCL::Argument("files", "Source files").multi(),
SCL::Argument("dir", "Destination directory"),
});
cmd.addHelpOption();
cmd.setHandler([](const SCL::ParseResult &result) -> int {
std::cout << "[Sources]" << std::endl;
for (const auto &item : result.values("files")) {
std::cout << item.toString() << std::endl;
}
std::cout << "[Destination]" << std::endl;
std::cout << result.value("dir").toString() << std::endl;
return 0;
});
return SCL::Parser(cmd).invoke(argc, argv);
}
Running the code:
> ./mv --help
Description:
move files to directory
Usage:
mv <files>... <dir> [options]
Arguments:
<files> Source files
<dir> Destination directory
Options:
-h, --help Show help information
> ./mv 1 2
[Sources]
1
[Destination]
2
>./mv 1 2 3
[Sources]
1
2
[Destination]
3
If you are confused about some of the concepts of command line programs, you can learn the following, which will help you use this project.
See Concepts to learn more.
See Examples to learn more.
cmake -B build -G Ninja
cmake --build build --target all
cmake --build build --target install
find_package(syscmdline REQUIRED)
target_link_libraries(my_project PRIVATE syscmdline::syscmdline)
Minimize Size
Validity Check
SYSCMDLINE_ENABLE_VALIDITY_CHECK is defined, which reduces parsing performance. Therefore, this macro is enabled only in debug mode.This project is licensed under the MIT License.