-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path30_set_string_cli.mds
More file actions
50 lines (40 loc) · 2.1 KB
/
Copy path30_set_string_cli.mds
File metadata and controls
50 lines (40 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
id: "007"
---
## `--set` vs `--set-string` — end-to-end (v0.4.0, #152)
This file has one variable, `id`, defaulting to the string `"007"`. Override it
on the CLI to watch type coercion change the outcome. Run all four:
~~~bash
# (1) default — id keeps the frontmatter string "007"
mds build examples/edge-cases/30_set_string_cli.mds -o -
# (2) --set coerces "007" to the NUMBER 7 (leading zeros lost). The
# `id == "007"` branch below then compares number-vs-string and RAISES
# mds::type_mismatch (exit 1) — the pitfall --set-string exists to avoid.
mds build examples/edge-cases/30_set_string_cli.mds --set id=007 -o -
# (3) --set-string keeps "007" a STRING byte-for-byte — same result as (1).
mds build examples/edge-cases/30_set_string_cli.mds --set-string id=007 -o -
# (4) the same key in BOTH flags is a hard error (exit 1)
mds build examples/edge-cases/30_set_string_cli.mds --set id=1 --set-string id=007 -o -
~~~
Rendered id: {{id}}
~~~bash
# (5) duplicate --set key — a warning is emitted on stderr and the last value
# wins. Here id=99 (number); the id == "007" branch then type-mismatches
# (exit 1). Warning text: "variable 'id' is set more than once by --set;
# the last value wins"
mds build examples/edge-cases/30_set_string_cli.mds --set id=42 --set id=99 -o -
# (6) --quiet suppresses the warning (stderr is silent) but not the error.
# The type_mismatch error and exit 1 remain.
mds build examples/edge-cases/30_set_string_cli.mds --set id=42 --set id=99 --quiet -o -
~~~
Note: the duplicate-key warning (a non-fatal advisory) is distinct from the
hard error in invocation (4), where a key appears in BOTH `--set` and
`--set-string`. The warning fires for repeated `--set`, repeated `--set-string`,
or both; `--quiet` silences the warning in all three cases.
@if number(id) == 7:
- `number(id) == 7` — bridging to a number yields 7 in every mode; leading zeros are gone.
@end
@if id == "007":
- `id == "007"` — id is still the STRING "007" (invocation 1 or 3), leading zeros intact.
Under `--set id=007` this line is never reached: the comparison type-mismatches first.
@end