https://github.com/felixthec/cpp_click
A simple cpp implementation of the awesome python library click
https://github.com/felixthec/cpp_click
Last synced: about 2 months ago
JSON representation
A simple cpp implementation of the awesome python library click
- Host: GitHub
- URL: https://github.com/felixthec/cpp_click
- Owner: FelixTheC
- License: apache-2.0
- Created: 2023-08-08T20:25:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-09T19:50:48.000Z (over 1 year ago)
- Last Synced: 2025-02-10T00:45:01.618Z (3 months ago)
- Language: C++
- Size: 33.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CPP click
A simple cpp implementation of the awesome python library [click](https://palletsprojects.com/p/click/)## What features are implemented
currently following features in a simple version are implemented
- options
- arguments## How to install via conan
- install [conan](https://docs.conan.io/2/installation.html)
- clone project via git
- in the project DIR run
```shell
conan create . -s build_type=Release
```## How to use
```c++
#include
#include#include "click.hpp"
#include "clickArgument.hpp"
#include "clickOption.hpp"namespace fs = std::filesystem;
void create_commandline_args(click::Click &cppClick);
int main(int argv, char *argc[])
{
click::Click cppClick {"isort"};
create_commandline_args(cppClick);cppClick.parse_commandline_args(argv, argc);
if (cppClick.help_called)
{
cppClick.display_help_text();
}
else
{
auto path = cppClick.get_argument("file_path").value()->get_value();
auto check_only = cppClick.get_option("check").value()->get_value();
...
}return EXIT_SUCCESS;
}void create_commandline_args(click::Click &cppClick)
{
click::Option isortOption {"check"};
click::Argument fileArg {"file_path",
[](const std::string &val) -> std::string
{
bool validFile = (fs::is_regular_file(val) &&
isort::utils::is_cpp_file(val)) ||
fs::is_directory(val);
if (validFile)
{
return val;
}
else
{
throw std::invalid_argument("Incorrect file path.: '" + val + "'");
}
}};
cppClick.arguments.emplace_back(std::make_unique(std::move(fileArg)));
cppClick.options.emplace_back(std::make_unique(std::move(isortOption)));
}```