def global_go

cli@0.2.0.0 · cli.bend:2554

import cli@0.2.0.0/cli.bend as Cli
import Base

2554# What items pass down to their subcommands, in their order: each global()
2555# arg, and each exclusive or need_one rule over a group whose args in all are
2556# each global(), so that it holds in every subcommand below.
2557def global_go(items: List<&2, Item>, +all: List<&2, Item>) ->
2558    List<&2, Item>:
2559  match items:
2560    case Nil{}: Nil{}
2561    case Arg{usage, help, +attrs} <> tail:
2562      +rest = global_go(tail, all)
2563      Bool.pick(List<&2, Item>, has_global(attrs),
2564        Arg{usage, help, attrs} <> rest, rest)
2565    case Exclusive{+name} <> tail:
2566      +rest = global_go(tail, all)
2567      Bool.pick(List<&2, Item>, group_global(all, name),
2568        Exclusive{name} <> rest, rest)
2569    case NeedOne{+name} <> tail:
2570      +rest = global_go(tail, all)
2571      Bool.pick(List<&2, Item>, group_global(all, name),
2572        NeedOne{name} <> rest, rest)
2573    case head <> tail: global_go(tail, all)

Uses (5)

Used by (1)