def zsh_branch

cli@0.2.0.0 · cli.bend:6910

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

6910# The body of a command with subcommands: its specs end in a state that
6911# offers them, completes help's tree, or enters the arm of the one given.
6912def zsh_branch(+entries: List<&2, Entry>, specs: List<&2, String>,
6913    +items: List<&2, Item>, +name: String, +words: List<&2, String>,
6914    arms: List<&2, String>, +ind: String) -> List<&2, String>:
6915  +state = String.join(name <> words, "-")
6916  +i2 = String.append(ind, "    ")
6917  +hstate = String.append(state, "-help")
6918  +label = zsh_label(name, words)
6919  List.concat(&2, String, [
6920    zsh_ends(words, ind),
6921    last_with(zsh_args(ind, List.append(&2, String, specs,
6922      [String.append("*:: :->", state)])), " && return"),
6923    [String.append(ind, "case $state in"),
6924      String.concat([ind, "  ", Sh.quote(state), ")"]),
6925      zsh_past_end(i2),
6926      String.append(i2, "if (( CURRENT == 1 )); then")],
6927    zsh_commands(entries, True{}, label, String.append(i2, "  ")),
6928    [String.append(i2, "else"), String.append(i2, "  case $words[1] in")],
6929    arms,
6930    [String.append(i2, "    'help')")],
6931    last_with(zsh_args(String.append(i2, "      "), ["(-h --help)-h[Print help]",
6932      "(-h --help)--help[Print help]", String.append("*:: :->", hstate)]),
6933      " && return"),
6934    [String.append(i2, "      case $state in"),
6935      String.concat([i2, "        ", Sh.quote(hstate), ")"]),
6936      zsh_past_end(String.append(i2, "          "))],
6937    last_with(zsh_help_tree(entries, label,
6938      zsh_help_arms(items, name, words, 1n,
6939        String.append(i2, "              ")),
6940      1n, String.append(i2, "          ")), " ;;"),
6941    [String.append(i2, "      esac ;;"), String.append(i2, "  esac"),
6942      String.append(i2, "fi ;;"), String.append(ind, "esac")],
6943  ])

Uses (19)

Used by (1)