Skip to content

Commit 9c71be1

Browse files
committed
add cmdline library
1 parent 4ac40cc commit 9c71be1

File tree

7 files changed

+49
-3
lines changed

7 files changed

+49
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target("templates_test")
2525
| name | introduce | demo | other |
2626
| --- | --- | --- | --- |
2727
| [templates](https://github.com/mcpplibs/templates) | A template of modern C++ `modules` libraries | [templates_test](tests/t/templates) | |
28+
| [cmdline](https://github.com/mcpplibs/cmdline) | A simple command-line parsing library/framework for modern C++ | [cmdline_test](tests/c/cmdline) | |
2829
| [llmapi](https://github.com/mcpplibs/llmapi) | Modern C++ LLM API client with openai-compatible support | [llmapi_test](tests/l/llmapi) | |
2930

3031
## Other

packages/c/cmdline/xmake.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package("cmdline")
2+
3+
set_homepage("https://github.com/mcpplibs/cmdline")
4+
set_description("A simple command-line parsing library/framework for modern C++")
5+
set_license("Apache-2.0")
6+
7+
add_urls(
8+
"https://github.com/mcpplibs/cmdline/archive/refs/tags/$(version).tar.gz",
9+
"https://github.com/mcpplibs/cmdline.git"
10+
)
11+
12+
on_install(function (package)
13+
import("package.tools.xmake").install(package)
14+
end)

tests/c/cmdline/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// more-details: https://github.com/mcpplibs/cmdline
2+
import std;
3+
import mcpplibs.cmdline;
4+
5+
using namespace mcpplibs;
6+
7+
int main(int argc, char* argv[]) {
8+
auto app = cmdline::App("myapp")
9+
.version("1.0.0")
10+
.description("A demo CLI")
11+
.arg("input").required().help("Input file")
12+
.option("verbose").short_name('v').help("Verbose output")
13+
.option("config").short_name('c').takes_value().value_name("FILE").help("Config file")
14+
.action([](const cmdline::ParsedArgs& p) {
15+
if (p.is_flag_set("verbose")) std::println("Verbose on");
16+
if (auto c = p.value("config")) std::println("Config: {}", *c);
17+
std::println("Input: {}", p.positional(0));
18+
});
19+
20+
return app.run(argc, argv);
21+
}

tests/c/cmdline/xmake.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
2+
3+
add_requires("cmdline", {system = false})
4+
5+
target("cmdline_test")
6+
set_kind("binary")
7+
set_languages("c++23")
8+
add_files("main.cpp")
9+
add_packages("cmdline")
10+
set_policy("build.c++.modules", true)

tests/l/llmapi/capi/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
1+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
22

33
add_requires("llmapi 0.0.1", {configs = { capi = true }})
44

tests/l/llmapi/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
1+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
22

33
add_requires("llmapi 0.0.2")
44

tests/t/templates/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
1+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
22

33
add_requires("templates 0.0.1")
44
--add_requires("mcpplibs-index::templates 0.0.1") -- TODO: impl prefix support in xmake

0 commit comments

Comments
 (0)