Skip to content

Commit 499eb77

Browse files
authored
mcpplibs.cmdline 0.0.3: value_type<T>() and value_as<T>() (#742)
* mcpplibs.cmdline 0.0.3: value_type<T>() — numeric options checked by the parse; value_as<T>() reads them back * tests/examples/cmdline: the dependency by its identity, mcpplibs.cmdline — what the scan finds a candidate's consumer by
1 parent 5291904 commit 499eb77

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
### Added
2424

25+
- **mcpplibs.cmdline 0.0.3.** `value_type<T>()` 声明选项取 `T` 类型的数字,解析时用 `std::from_chars` 校验,不合法即解析错误;
26+
`value_as<T>()` 读回。测试成员移到 0.0.3,并检验这两项。
2527
- **mtest 0.5.2.** 四个包的 0.5.2:自启动副本的测试以对象 `child` 声明副本所做之事、以 `child_command` 启动之,
2628
故不再定义 `main`,同一目录的文件可为一个程序;库对 mcpplibs.os 的要求为 `^0.4.1`。测试成员移到 0.5.2。
2729
- **mtest 0.5.1.** 四个包的 0.5.1:协议标记在只保留可达部分的链接(`--gc-sections`)中保留,`mcpp test`

‎pkgs/c/cmdline.lua‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
-- Form B (inline mcpp = { ... }) carries the build info for ALL listed versions.
22
-- 0.0.2+ ships an upstream `mcpp.toml`, but `mcpp` is a package-level field
33
-- (not per-version) in xpkg.lua, so to keep 0.0.1 installable we keep the
4-
-- workaround table here. The src/**/*.cppm layout is identical across 0.0.1
5-
-- and 0.0.2, so a single Form B block describes both versions correctly.
4+
-- workaround table here. The src/**/*.cppm layout is the same across 0.0.1,
5+
-- 0.0.2 and 0.0.3 (0.0.3 adds src/completions*.cppm, which the glob takes in),
6+
-- so a single Form B block describes every version correctly.
67
-- When 0.0.1 is dropped, this can be replaced with `mcpp = "*/mcpp.toml"`.
78
--
89
-- M6.x: Form B paths are globs relative to the verdir (the untouched
@@ -33,6 +34,13 @@ package = {
3334
},
3435
sha256 = "4f3e2b8dc4d9f11bdd9a784a9914e889234ac305e1020282ffa03f506b75d52a",
3536
},
37+
["0.0.3"] = {
38+
url = {
39+
GLOBAL = "https://github.com/mcpplibs/cmdline/archive/refs/tags/v0.0.3.tar.gz",
40+
CN = "https://gitcode.com/mcpp-res/cmdline/releases/download/0.0.3/cmdline-0.0.3.tar.gz",
41+
},
42+
sha256 = "a7854898e083f6df203ef7f14ec668812f3a5c28739fdc84d05d9dc39b990ca0",
43+
},
3644
},
3745
macosx = {
3846
["0.0.1"] = {
@@ -49,6 +57,13 @@ package = {
4957
},
5058
sha256 = "4f3e2b8dc4d9f11bdd9a784a9914e889234ac305e1020282ffa03f506b75d52a",
5159
},
60+
["0.0.3"] = {
61+
url = {
62+
GLOBAL = "https://github.com/mcpplibs/cmdline/archive/refs/tags/v0.0.3.tar.gz",
63+
CN = "https://gitcode.com/mcpp-res/cmdline/releases/download/0.0.3/cmdline-0.0.3.tar.gz",
64+
},
65+
sha256 = "a7854898e083f6df203ef7f14ec668812f3a5c28739fdc84d05d9dc39b990ca0",
66+
},
5267
},
5368
windows = {
5469
["0.0.1"] = {
@@ -65,6 +80,13 @@ package = {
6580
},
6681
sha256 = "4f3e2b8dc4d9f11bdd9a784a9914e889234ac305e1020282ffa03f506b75d52a",
6782
},
83+
["0.0.3"] = {
84+
url = {
85+
GLOBAL = "https://github.com/mcpplibs/cmdline/archive/refs/tags/v0.0.3.tar.gz",
86+
CN = "https://gitcode.com/mcpp-res/cmdline/releases/download/0.0.3/cmdline-0.0.3.tar.gz",
87+
},
88+
sha256 = "a7854898e083f6df203ef7f14ec668812f3a5c28739fdc84d05d9dc39b990ca0",
89+
},
6890
},
6991
},
7092

‎tests/examples/cmdline/mcpp.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ name = "cmdline-tests"
1010
version = "0.1.0"
1111

1212
[dependencies]
13-
cmdline = "0.0.2"
13+
mcpplibs.cmdline = "0.0.3"

‎tests/examples/cmdline/tests/consume.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ int main() {
4141
check(!missing.has_value() || missing.error().is_error(),
4242
"a missing required argument is refused");
4343

44+
// 0.0.3: a numeric option is checked by the parse and read back typed.
45+
auto numbers = cmdline::App("tool").option(cmdline::Option("rate").value_type<double>()).option(cmdline::Option("count").value_type<int>());
46+
auto typed = numbers.parse_from("tool --rate 2.5 --count=3");
47+
check(typed && typed->value_as<double>("rate") == 2.5 && typed->value_as<int>("count") == 3, "numbers read back as their types");
48+
auto wrong = numbers.parse_from("tool --count 3px");
49+
check(!wrong && wrong.error().is_error(), "a value that is not a number of the type is refused");
50+
4451
if (failures == 0) std::println("cmdline: ok");
4552
return failures == 0 ? 0 : 1;
4653
}

0 commit comments

Comments
 (0)