| 133 | aux(command) |
| 134 | |
| 135 | def write_cmd(self, command): |
| 136 | assert len(command.arguments) == 0 |
| 137 | assert len(command.subcommands) > 0 |
| 138 | subhelp = [] |
| 139 | subrun = [] |
| 140 | for sub in command.subcommands: |
| 141 | subhelp.append("'" + sub.name + "':'" + sub.help + "'") |
| 142 | r = "(" + sub.name + ")" |
| 143 | r += "\n " + "_" + sub.full_name().replace(" ", "_") |
| 144 | r += "\n ;;" |
| 145 | subrun.append(r) |
| 146 | self.writeln("_" + command.full_name().replace(" ", "_") + """ () |
| 147 | { |
| 148 | local curcontext="$curcontext" state line |
| 149 | typeset -A opt_args |
| 150 | |
| 151 | _arguments -C \\ |
| 152 | ':command:->command' \\ |
| 153 | '*::options:->options' |
| 154 | |
| 155 | case $state in |
| 156 | (command) |
| 157 | |
| 158 | local -a subcommands |
| 159 | subcommands=( |
| 160 | """ + "\n ".join(subhelp) + """ |
| 161 | ) |
| 162 | _describe -t commands '""" + command.full_name() + """' subcommands |
| 163 | ;; |
| 164 | |
| 165 | (options) |
| 166 | case $line[1] in |
| 167 | |
| 168 | """ + "\n\n ".join(subrun) + """ |
| 169 | |
| 170 | esac |
| 171 | ;; |
| 172 | esac |
| 173 | }""") |
| 174 | |
| 175 | def write_arguments(self, name, args): |
| 176 | def esc(s): |