Exemple #1
0
    public function render()
    {
        $def = $this->command->definition();
        $bashFunction = str_replace('-', '_', $def->name);
        ?>
#!/bin/bash

# Bash Completion for <?php 
        echo $def->description;
        ?>

_<?php 
        echo $bashFunction;
        ?>
() {
COMPREPLY=()
local self=${COMP_WORDS[0]}
local action=${COMP_WORDS[1]}
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local options=()

<?php 
        $this->renderDefinition($def);
        ?>

case "$action" in
<?php 
        foreach ($def->actions as $name => $commandDefinition) {
            ?>
    "<?php 
            echo $name;
            ?>
")
    <?php 
            $this->renderDefinition($commandDefinition, 2);
            ?>
    ;;
<?php 
        }
        ?>
esac


if [[ ${cur} == -* ]] ; then
    COMPREPLY=( $( compgen -W "${options[*]}" -- $cur) )
    return 0
fi

COMPREPLY=( $( compgen -W "${options[*]}" -- $cur) )
}

complete -F _<?php 
        echo $bashFunction;
        ?>
 -o default <?php 
        echo $def->name;
    }
Exemple #2
0
 public function run(Request $request = null)
 {
     if (null === $request) {
         $request = Request::createAuto();
     }
     $this->request = $request;
     try {
         if (!$this->command instanceof Application) {
             throw new Command\Exception('Application required', Command\Exception::INVALID_ARGUMENT);
         }
         $this->reader = new RequestMapper();
         $this->reader->read($request, $this->command->optionsArray());
     } catch (Command\Exception $exception) {
         if (empty($this->reader->values['action'])) {
             // TODO symbolize 'action' literal
             $this->response->error($exception->getMessage());
             $this->response->addContent('Use --help to show information.');
             return $this;
         }
     }
     foreach ($this->reader->values as $name => $value) {
         $this->command->{$name} = $value;
     }
     if (isset($this->command->action)) {
         $action = $this->command->action;
         $commandDefinition = $this->command->definition()->actions[$action];
         $command = new $commandDefinition->commandClass();
         $runner = new \Yaoi\Cli\Command\Runner($command);
         $runner->commandName = $this->commandName . ' ' . $action;
         $runner->commandVersion = $this->commandVersion;
         $runner->commandDescription = $this->commandDescription . ($runner->commandDescription ? PHP_EOL . $runner->commandDescription : '');
         $runner->skipFirstTokens = 1;
         $runner->run($request);
     } elseif (!empty($this->reader->values[self::HELP])) {
         $this->showHelp();
     } elseif (!empty($this->reader->values[self::VERSION])) {
         $this->showVersion();
     } elseif (!empty($this->reader->values[self::BASH_COMPLETION])) {
         $this->showBashCompletion();
     } elseif (!empty($this->reader->values[self::INSTALL])) {
         $this->install();
     }
     // @codeCoverageIgnoreEnd
     return $this;
 }