Exemplo n.º 1
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     $args = $this->argv->getRemainingArgs();
     if (count($args) != 1 || $args[0] != 'execute') {
         throw new ArgvException('', $this->getUsage());
     }
     CronjobScheduler::getInstance()->executeCronjobs();
 }
Exemplo n.º 2
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     $args = $this->argv->getRemainingArgs();
     // validate parameters
     if (count($args) != 1) {
         throw new ArgvException('', $this->getUsage());
     }
     $commands = CLICommandHandler::getCommands();
     if (!isset($commands[$args[0]])) {
         throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.cli.error.command.notFound', array('command' => $args[0])), $this->getUsage());
     }
     $command = $commands[$args[0]];
     if (!$command instanceof IArgumentedCLICommand) {
         throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.cli.error.help.noArguments', array('command' => $args[0])), $this->getUsage());
     }
     CLIWCF::getReader()->println($command->getUsage());
 }
Exemplo n.º 3
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     if (count($this->argv->getRemainingArgs()) !== 2) {
         throw new ArgvException('', $this->fixUsage($this->argv->getUsageMessage()));
     }
     list($action, $package) = $this->argv->getRemainingArgs();
     CLIWCF::getReader()->setHistoryEnabled(false);
     switch ($action) {
         case 'install':
             $this->install($package);
             break;
         case 'uninstall':
             $this->uninstall($package);
             break;
         default:
             throw new ArgvException('', $this->fixUsage($this->argv->getUsageMessage()));
             break;
     }
 }
Exemplo n.º 4
0
    public function testGetoptCheckParameterType()
    {
        $opts = new Getopt(array(
            'apple|a=i' => 'apple with integer',
            'banana|b=w' => 'banana with word',
            'pear|p=s' => 'pear with string',
            'orange|o-i' => 'orange with optional integer',
            'lemon|l-w' => 'lemon with optional word',
            'kumquat|k-s' => 'kumquat with optional string'));

        $opts->setArguments(array('-a', 327));
        $opts->parse();
        $this->assertEquals(327, $opts->a);

        $opts->setArguments(array('-a', 'noninteger'));
        try {
            $opts->parse();
            $this->fail('Expected to catch \Zend\Console\Exception\RuntimeException');
        } catch (\Zend\Console\Exception\RuntimeException $e) {
            $this->assertEquals($e->getMessage(), 'Option "apple" requires an integer parameter, but was given "noninteger".');
        }

        $opts->setArguments(array('-b', 'word'));
        $this->assertEquals('word', $opts->b);

        $opts->setArguments(array('-b', 'two words'));
        try {
            $opts->parse();
            $this->fail('Expected to catch \Zend\Console\Exception\RuntimeException');
        } catch (\Zend\Console\Exception\RuntimeException $e) {
            $this->assertEquals($e->getMessage(), 'Option "banana" requires a single-word parameter, but was given "two words".');
        }

        $opts->setArguments(array('-p', 'string'));
        $this->assertEquals('string', $opts->p);

        $opts->setArguments(array('-o', 327));
        $this->assertEquals(327, $opts->o);

        $opts->setArguments(array('-o'));
        $this->assertTrue($opts->o);

        $opts->setArguments(array('-l', 'word'));
        $this->assertEquals('word', $opts->l);

        $opts->setArguments(array('-k', 'string'));
        $this->assertEquals('string', $opts->k);

    }
Exemplo n.º 5
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     if ($this->argv->list) {
         CLIWCF::getReader()->println(CLIUtil::generateTable($this->generateList()));
         return;
     }
     $args = $this->argv->getRemainingArgs();
     // validate parameters
     if (count($args) != 1) {
         throw new ArgvException('', $this->getUsage());
     }
     $class = $args[0];
     // assume wcf\system\worker when no FQN is given
     if (strpos($class, '\\') === false) {
         $class = 'wcf\\system\\worker\\' . $class;
     }
     $invalid = false;
     if (!class_exists($class)) {
         $invalid = true;
     } else {
         $reflection = new \ReflectionClass($class);
         if (!$reflection->isInstantiable()) {
             $invalid = true;
         } else {
             if (!ClassUtil::isInstanceOf($class, 'wcf\\system\\worker\\IWorker')) {
                 $invalid = true;
             }
         }
     }
     if ($invalid) {
         throw new ArgvException("Invalid worker '" . $class . "' given", $this->getUsage());
     }
     // parse parameters
     $options = $this->argv->getOptions();
     $parameters = array();
     foreach ($options as $option) {
         $value = $this->argv->getOption($option);
         if ($option === 'setParameter') {
             if (!is_array($value)) {
                 $value = array($value);
             }
             foreach ($value as $parameter) {
                 list($parameterKey, $parameterValue) = explode('=', $parameter);
                 $parameters[$parameterKey] = $parameterValue;
             }
         } else {
             $parameters[$option] = $value;
         }
     }
     $worker = new $class($parameters);
     $worker->validate();
     $worker->getProgress();
     // make sure objects are counted
     // initialize progressbar
     $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth())));
     $progress = 0;
     for ($i = 0; $progress < 100; $i++) {
         $worker->setLoopCount($i);
         $worker->validate();
         // execute worker
         $worker->execute();
         // update progress
         $progress = $worker->getProgress();
         $progressbar->update($progress);
     }
     $progressbar->update($progress);
     $progressbar->getAdapter()->finish();
 }