Esempio n. 1
0
 /**
  * Execute command
  * 
  * @param array $args
  * @param array $options
  */
 public function execute(array $args, array $options = array())
 {
     if (empty($args)) {
         $this->showUsage();
         $this->showCommands();
     } else {
         $this->showHelp($args[0], Utils::get($args, 1));
     }
 }
Esempio n. 2
0
 /**
  * Execute command
  * 
  * @param array $args
  * @param array $options
  */
 public function execute(array $args, array $options = array())
 {
     if (!empty($options['version'])) {
         return $this->showVersion();
     }
     if (empty($args)) {
         $this->writeln("DBVC - Database version control\n");
         $this->showUsage();
         $this->showOptions();
         $this->showCommands();
     } else {
         $this->showHelp($args[0], Utils::get($args, 1));
     }
 }
Esempio n. 3
0
 /**
  * If not overriden, will execute the command specified
  * as the first argument
  * 
  * Commands must be defined as methods named after the
  * command, prefixed with execute (eg. create -> executeCreate)
  * 
  * @param array $args
  * @param array $options
  */
 public function execute(array $args, array $options = array())
 {
     if (!count($args)) {
         throw new ConsoleException("Missing subcommand name");
     }
     $command = ucfirst(Utils::camelize(array_shift($args)));
     $methodName = "execute{$command}";
     if (!method_exists($this, $methodName)) {
         throw new ConsoleException("Command '{$command}' does not exist");
     }
     $method = new ReflectionMethod($this, $methodName);
     $params = Utils::computeFuncParams($method, $args, $options);
     return $method->invokeArgs($this, $params);
 }
Esempio n. 4
0
 public function execute(array $args, array $options = array())
 {
     if (empty($args)) {
         $formater = new ConsoleKit\TextFormater(array('quote' => ' * '));
         $this->writeln('Available commands:', ConsoleKit\Colors::BLACK | ConsoleKit\Colors::BOLD);
         foreach ($this->console->getCommands() as $name => $fqdn) {
             if ($fqdn !== __CLASS__) {
                 $this->writeln($formater->format($name));
             }
         }
         $this->writeln("Use 'clamp help command' for more info");
     } else {
         $commandFQDN = $this->console->getCommand($args[0]);
         $help = ConsoleKit\Help::fromFQDN($commandFQDN, ConsoleKit\Utils::get($args, 1));
         $this->writeln($help);
     }
 }
Esempio n. 5
0
 /**
  * Creates an Help object from a class subclassing Command
  *
  * @param string $name
  * @param string $subCommand
  * @return Help
  */
 public static function fromCommandClass($name, $subCommand = null)
 {
     $prefix = 'execute';
     $class = new ReflectionClass($name);
     if ($subCommand) {
         $method = $prefix . ucfirst(Utils::camelize($subCommand));
         if (!$class->hasMethod($method)) {
             throw new ConsoleException("Sub command '{$subCommand}' of '{$name}' does not exist");
         }
         return new Help($class->getMethod($method)->getDocComment());
     }
     $help = new Help($class->getDocComment());
     foreach ($class->getMethods() as $method) {
         if (strlen($method->getName()) > strlen($prefix) && substr($method->getName(), 0, strlen($prefix)) === $prefix) {
             $help->subCommands[] = Utils::dashized(substr($method->getName(), strlen($prefix)));
         }
     }
     return $help;
 }
Esempio n. 6
0
 /**
  * Executes a command
  *
  * @param string $command
  * @param array $args
  * @param array $options
  * @return mixed
  */
 public function execute($command = null, array $args = array(), array $options = array())
 {
     $command = $command ?: $this->defaultCommand;
     if (!isset($this->commands[$command])) {
         throw new ConsoleException("Command '{$command}' does not exist");
     }
     $callback = $this->commands[$command];
     if (is_callable($callback)) {
         $params = array($args, $options);
         if (is_string($callback)) {
             if (strpos($callback, '::') !== false) {
                 list($classname, $methodname) = explode('::', $callback);
                 $reflection = new ReflectionMethod($classname, $methodname);
             } else {
                 $reflection = new ReflectionFunction($callback);
             }
             $params = Utils::computeFuncParams($reflection, $args, $options);
         }
         $params[] = $this;
         return call_user_func_array($callback, $params);
     }
     $method = new ReflectionMethod($callback, 'execute');
     $params = Utils::computeFuncParams($method, $args, $options);
     return $method->invokeArgs(new $callback($this), $params);
 }
Esempio n. 7
0
 public function testDashized()
 {
     $this->assertEquals('foo-bar', Utils::dashized('fooBar'));
 }
Esempio n. 8
0
 public function execute(array $args, array $options = array())
 {
     $this->context(array('fgcolor' => Utils::get($options, 'color')), function ($c) use($args) {
         $c->writeln(sprintf('hello %s!', $args[0]));
     });
 }