fmt/code.bend

cswap-bend-cli@0.1.0.0 · 19 lines · 3 definitions

1import Base
2
3# The output formats as small numbers, for records that cannot name the Fmt
4# type (the `auto` flags): 0 text, 1 json, 2 csv, 3 yaml, 4 toon. out.bend
5# turns a code into a Fmt.
6
7# The code of a `--format` argument, none for an unknown name.
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() ++ ")"