catch (ArgvException $e) {
// show error message and usage
if ($e->getMessage()) echo $e->getMessage().PHP_EOL;
- echo str_replace($_SERVER['argv'][0], CLICommandHandler::getCommandName($line), $e->getUsageMessage());
+ echo $e->getUsageMessage();
if (self::getArgvParser()->exitOnFail) {
exit(1);
* @subpackage system.cli.command
* @category Community Framework
*/
-class CronjobCLICommand implements ICLICommand {
+class CronjobCLICommand implements IArgumentedCLICommand {
+ /**
+ * arguments parser
+ * @var \Zend\Console\Getopt
+ */
+ protected $argv = null;
+
+ /**
+ * Initializes the argument parser.
+ */
+ public function __construct() {
+ $this->argv = new ArgvParser(array());
+ }
+
/**
* @see \wcf\system\cli\command\ICLICommand::execute()
*/
public function execute(array $parameters) {
- $argv = new ArgvParser(array());
- $argv->setArguments($parameters);
- $argv->parse();
+ $this->argv->setArguments($parameters);
+ $this->argv->parse();
- $args = $argv->getRemainingArgs();
+ $args = $this->argv->getRemainingArgs();
if (count($args) != 1 || $args[0] != 'execute') {
- throw new ArgvException('', $this->fixUsage($argv->getUsageMessage()));
+ throw new ArgvException('', $this->getUsage());
}
CronjobScheduler::getInstance()->executeCronjobs();
}
/**
- * Returns fixed usage message of ArgvParser.
- *
- * @param string $usage
- * @return string
+ * @see \wcf\system\cli\command\ICLICommand::getUsage()
*/
- public function fixUsage($usage) {
- return str_replace($_SERVER['argv'][0].' [ options ]', $_SERVER['argv'][0].' [ options ] execute', $usage);
+ public function getUsage() {
+ return str_replace($_SERVER['argv'][0].' [ options ]', 'cronjob [ options ] execute', $this->argv->getUsageMessage());
}
/**
--- /dev/null
+<?php
+namespace wcf\system\cli\command;
+use wcf\system\CLIWCF;
+use wcf\util\CLIUtil;
+use wcf\util\DirectoryUtil;
+use wcf\util\StringUtil;
+use Zend\Console\Exception\RuntimeException as ArgvException;
+use Zend\Console\Getopt as ArgvParser;
+
+/**
+ * Shows command usage.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2013 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cli.command
+ * @category Community Framework
+ */
+class HelpCLICommand implements IArgumentedCLICommand {
+ /**
+ * arguments parser
+ * @var \Zend\Console\Getopt
+ */
+ protected $argv = null;
+
+ /**
+ * Initializes the argument parser.
+ */
+ public function __construct() {
+ $this->argv = new ArgvParser(array());
+ $this->argv->setOptions(array(
+ ArgvParser::CONFIG_FREEFORM_FLAGS => true,
+ ArgvParser::CONFIG_PARSEALL => false,
+ ArgvParser::CONFIG_CUMULATIVE_PARAMETERS => true
+ ));
+ }
+
+ /**
+ * @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());
+ }
+
+ /**
+ * @see \wcf\system\cli\command\ICLICommand::getUsage()
+ */
+ public function getUsage() {
+ return str_replace($_SERVER['argv'][0].' [ options ]', 'help [ options ] <command>', $this->argv->getUsageMessage());
+ }
+
+ /**
+ * @see \wcf\system\cli\command\ICLICommand::canAccess()
+ */
+ public function canAccess() {
+ return true;
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\cli\command;
+
+/**
+ * Represents a command with arguments.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2013 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.cli.command
+ * @category Community Framework
+ */
+interface IArgumentedCLICommand extends ICLICommand {
+ /**
+ * Returns the usage text.
+ *
+ * @return string
+ */
+ public function getUsage();
+}
* @subpackage system.cli.command
* @category Community Framework
*/
-class PackageCLICommand implements ICLICommand {
+class PackageCLICommand implements IArgumentedCLICommand {
/**
* arguments parser
* @var \Zend\Console\Getopt
*/
- private $argv = null;
+ protected $argv = null;
+
+ /**
+ * Initializes the argument parser.
+ */
+ public function __construct() {
+ $this->argv = new ArgvParser(array());
+ }
/**
* @see \wcf\system\cli\command\ICLICommand::execute()
*/
public function execute(array $parameters) {
- $this->argv = new ArgvParser(array());
$this->argv->setArguments($parameters);
$this->argv->parse();
Log::error('package.'.$name.':'.JSON::encode($parameters));
if ($parameters) {
- throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.acp.package.error.'.$name, $parameters), $this->fixUsage($this->argv->getUsageMessage()));
+ throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.acp.package.error.'.$name, $parameters), $this->getUsage());
}
else {
- throw new ArgvException(CLIWCF::getLanguage()->get('wcf.acp.package.error.'.$name), $this->fixUsage($this->argv->getUsageMessage()));
+ throw new ArgvException(CLIWCF::getLanguage()->get('wcf.acp.package.error.'.$name), $this->argv->getUsageMessage());
}
}
/**
- * Returns fixed usage message of ArgvParser.
- *
- * @param string $usage
- * @return string
+ * @see \wcf\system\cli\command\ICLICommand::getUsage()
*/
- public function fixUsage($usage) {
- return str_replace($_SERVER['argv'][0].' [ options ]', $_SERVER['argv'][0].' [ options ] <install|uninstall> <package>', $usage);
+ public function getUsage() {
+ return str_replace($_SERVER['argv'][0].' [ options ]', 'package [ options ] <install|uninstall> <package>', $this->argv->getUsageMessage());
}
/**
* @subpackage system.cli.command
* @category Community Framework
*/
-class WorkerCLICommand implements ICLICommand {
+class WorkerCLICommand implements IArgumentedCLICommand {
/**
- * @see \wcf\system\cli\command\ICLICommand::execute()
+ * arguments parser
+ * @var \Zend\Console\Getopt
*/
- public function execute(array $parameters) {
- $argv = new ArgvParser(array(
- 'l|list' => 'Lists available workers',
- 'setParameter=s' => 'Sets a parameter given to the worker'
+ protected $argv = null;
+
+ /**
+ * Initializes the argument parser.
+ */
+ public function __construct() {
+ $this->argv = new ArgvParser(array(
+ 'l|list' => CLIWCF::getLanguage()->get('wcf.cli.worker.list'),
+ 'setParameter=s' => CLIWCF::getLanguage()->get('wcf.cli.worker.setParameter')
));
- $argv->setOptions(array(
+ $this->argv->setOptions(array(
ArgvParser::CONFIG_FREEFORM_FLAGS => true,
ArgvParser::CONFIG_PARSEALL => false,
ArgvParser::CONFIG_CUMULATIVE_PARAMETERS => true
));
- $argv->setArguments($parameters);
- $argv->parse();
+ }
+
+ /**
+ * @see \wcf\system\cli\command\ICLICommand::execute()
+ */
+ public function execute(array $parameters) {
+ $this->argv->setArguments($parameters);
+ $this->argv->parse();
- if ($argv->list) {
+ if ($this->argv->list) {
CLIWCF::getReader()->println(CLIUtil::generateTable($this->generateList()));
return;
}
- $args = $argv->getRemainingArgs();
+ $args = $this->argv->getRemainingArgs();
// validate parameters
if (count($args) != 1) {
- throw new ArgvException('', str_replace($_SERVER['argv'][0].' [ options ]', $_SERVER['argv'][0].' [ options ] <worker>', $argv->getUsageMessage()));
+ throw new ArgvException('', $this->getUsage());
}
$class = $args[0];
}
}
if ($invalid) {
- throw new ArgvException("Invalid worker '".$class."' given", $argv->getUsageMessage());
+ throw new ArgvException("Invalid worker '".$class."' given", $this->getUsage());
}
// parse parameters
- $options = $argv->getOptions();
+ $options = $this->argv->getOptions();
$parameters = array();
foreach ($options as $option) {
- $value = $argv->getOption($option);
+ $value = $this->argv->getOption($option);
if ($option === 'setParameter') {
if (!is_array($value)) {
$value = array($value);
return $table;
}
+ /**
+ * @see \wcf\system\cli\command\ICLICommand::getUsage()
+ */
+ public function getUsage() {
+ return str_replace($_SERVER['argv'][0].' [ options ]', 'worker [ options ] <worker>', $this->argv->getUsageMessage());
+ }
+
/**
* @see \wcf\system\cli\command\ICLICommand::canAccess()
*/
- Befehle, welche ihre Aktion nicht erfolgreich ausführen konnten
- Systemfehler]]></item>
<item name="wcf.cli.help.packageID"><![CDATA[Die Anwendung mit der angegebenen Paket-ID wird als Standard für diese Sitzung verwendet.]]></item>
+
+ <item name="wcf.cli.worker.setParameter"><![CDATA[Übergibt einen Parameter an den Worker. Bsp.: --setParameter param=wert]]></item>
+ <item name="wcf.cli.worker.list"><![CDATA[Listet alle Worker auf.]]></item>
+
+ <item name="wcf.cli.error.help.noArguments"><![CDATA[Der Befehl "{$command}" unterstützt keine Parameter.]]></item>
<item name="wcf.cli.error.language.notFound"><![CDATA[Die Sprache mit dem Sprachcode "{$languageCode}" konnte nicht gefunden werden.]]></item>
- <item name="wcf.cli.error.command.notFound"><![CDATA[Der Befehl "{$command}" konnte nicht gefunden werden.]]></item>
+ <item name="wcf.cli.error.command.notFound"><![CDATA[Der Befehl "{$command}" konnte nicht gefunden werden. Benutze "commands", um verfügbare Befehle aufzulisten.]]></item>
</category>
<category name="wcf.clipboard">
- Core errors]]></item>
<item name="wcf.cli.help.packageID"><![CDATA[The given package id will be used as a default for this session.]]></item>
+ <item name="wcf.cli.worker.setParameter"><![CDATA[Sets a worker parameter e.g.: --setParameter param=value]]></item>
+ <item name="wcf.cli.worker.list"><![CDATA[Lists all workers.]]></item>
+
+ <item name="wcf.cli.error.help.noArguments"><![CDATA[The command "{$command}" does not support any parameters.]]></item>
<item name="wcf.cli.error.language.notFound"><![CDATA[The language with the language code "{$languageCode}" could not be found.]]></item>
- <item name="wcf.cli.error.command.notFound"><![CDATA[The command "{$command}" could not be found.]]></item>
+ <item name="wcf.cli.error.command.notFound"><![CDATA[The command "{$command}" could not be found. Type in "commands" to list available commands.]]></item>
</category>
<category name="wcf.clipboard">