public function complete_with_subcommands(CommandBase $cmd, $level = 1) { $cmdSignature = $cmd->getSignature(); $buf = new Buffer(); $buf->setIndent($level); $subcmds = $this->visible_commands($cmd->getCommands()); $descsBuf = $this->describe_commands($subcmds, $level); $code = array(); // $code[] = 'echo $words[$CURRENT-1]'; $buf->appendLine("_arguments -C \\"); $buf->indent(); if ($args = $this->command_flags($cmd, $cmdSignature)) { foreach ($args as $arg) { $buf->appendLine($arg . " \\"); } } $buf->appendLine("': :->cmds' \\"); $buf->appendLine("'*:: :->option-or-argument' \\"); $buf->appendLine(" && return"); $buf->unindent(); $buf->appendLine("case \$state in"); $buf->indent(); $buf->appendLine("(cmds)"); $buf->appendBuffer($descsBuf); $buf->appendLine(";;"); $buf->appendLine("(option-or-argument)"); // $code[] = " curcontext=\${curcontext%:*:*}:$programName-\$words[1]:"; // $code[] = " case \$words[1] in"; $buf->indent(); $buf->appendLine("curcontext=\${curcontext%:*}-\$line[1]:"); $buf->appendLine("case \$line[1] in"); $buf->indent(); foreach ($subcmds as $k => $subcmd) { // TODO: support alias $buf->appendLine("({$k})"); if ($subcmd->hasCommands()) { $buf->appendBlock($this->complete_with_subcommands($subcmd, $level + 1)); } else { $buf->appendBlock($this->complete_command_options_arguments($subcmd, $level + 1)); } $buf->appendLine(";;"); } $buf->unindent(); $buf->appendLine("esac"); $buf->appendLine(";;"); $buf->unindent(); $buf->appendLine("esac"); return $buf->__toString(); }
function command_signature_suffix(CommandBase $command) { return $command->getSignature(); // return str_replace('.','_', $command->getSignature()); }