public function __construct(CommandBase $parent = null) { parent::__construct($parent); }
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()); }
public function init() { // $this->addCommand('list','CLIFramework\\Command\\ListCommand'); parent::init(); $this->command('help', 'CLIFramework\\Command\\HelpCommand'); $this->commandGroup("Development Commands", array('zsh' => 'CLIFramework\\Command\\ZshCompletionCommand', 'bash' => 'CLIFramework\\Command\\BashCompletionCommand', 'meta' => 'CLIFramework\\Command\\MetaCommand', 'compile' => 'CLIFramework\\Command\\CompileCommand', 'archive' => 'CLIFramework\\Command\\ArchiveCommand', 'github:build-topics' => 'CLIFramework\\Command\\BuildGitHubWikiTopicsCommand'))->setId('dev'); }
private function addCommandsForParent($commands) { foreach ($commands as $command) { $this->parent->addCommand($command); } }
/** * connectCommand connects a command name with a command object. * * @param string $name * @param CLIFramework\CommandBase $cmd */ protected function connectCommand($name, CommandBase $cmd) { $cmd->setName($name); $this->commands[$name] = $cmd; // regsiter command aliases to the alias table. $aliases = $cmd->aliases(); if (is_string($aliases)) { $aliases = preg_split('/\\s+/', $aliases); } if (!is_array($aliases)) { throw new InvalidArgumentException("Aliases needs to be an array or a space-separated string."); } foreach ($aliases as $alias) { $this->aliases[$alias] = $cmd; } }