fmt/code.bend
cswap-bend-cli@0.1.0.0 · 19 lines · 3 definitions
1import Base
2
3
4
5
6
7
8def of_name(+s: String) -> Maybe<&2, U32>:
9 Bool.pick(Maybe<&2, U32>, String.eq(s, "text"), Some{0},
10 Bool.pick(Maybe<&2, U32>, String.eq(s, "json"), Some{1},
11 Bool.pick(Maybe<&2, U32>, String.eq(s, "csv"), Some{2},
12 Bool.pick(Maybe<&2, U32>, String.eq(s, "yaml") || String.eq(s, "yml"), Some{3},
13 Bool.pick(Maybe<&2, U32>, String.eq(s, "toon"), Some{4}, None{})))))
14
15def choices() -> String:
16 "'text', 'json', 'csv', 'yaml', 'toon'"
17
18def invalid(+flag: String, +v: String) -> String:
19 "argument " ++ flag ++ ": invalid choice: '" ++ v ++ "' (choose from " ++ choices() ++ ")"