GNU-style CLI flags, embedded data, and a literal format grammar #3
@@ -153,11 +153,15 @@ func compileChoice(items []any) (node, error) {
|
|||||||
func checkNoRepeatedItem(items []any) error {
|
func checkNoRepeatedItem(items []any) error {
|
||||||
seen := make(map[string]int, len(items))
|
seen := make(map[string]int, len(items))
|
||||||
for i, raw := range items {
|
for i, raw := range items {
|
||||||
key, err := json.Marshal(raw)
|
key, isString := raw.(string)
|
||||||
|
if !isString {
|
||||||
|
b, err := json.Marshal(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if j, dup := seen[string(key)]; dup {
|
key = "\x00" + string(b)
|
||||||
|
}
|
||||||
|
if j, dup := seen[key]; dup {
|
||||||
if s, isString := raw.(string); isString {
|
if s, isString := raw.(string); isString {
|
||||||
return fmt.Errorf("choice item %q is repeated; skew the odds with a weight instead: { \"format\": %q, \"weight\": 2 }", s, s)
|
return fmt.Errorf("choice item %q is repeated; skew the odds with a weight instead: { \"format\": %q, \"weight\": 2 }", s, s)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user