Yosymfony\Spress\Plugin\CommandDefinition::addOption PHP Method

addOption() public method

Adds a new command option.
public addOption ( string $name, string | array $shortcut = null, integer $mode = null, string $description = '', mixed $default = null )
$name string The option name
$shortcut string | array The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
$mode integer The option mode: One of the VALUE_* constants
$description string A description text
$default mixed The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
    public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
    {
        if (empty($name)) {
            throw new \InvalidArgumentException('An option name cannot be empty.');
        }
        if (null === $mode) {
            $mode = self::VALUE_NONE;
        } elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
            throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
        }
        $this->options[] = [$name, $shortcut, $mode, $description, $default];
    }

Usage Example

 /**
  * Gets the command's definition.
  *
  * @return \Yosymfony\Spress\Plugin\CommandDefinition Definition of the command.
  */
 public function getCommandDefinition()
 {
     $definition = new CommandDefinition('import:wordpress');
     $definition->setDescription('Import a blog from Wordpress');
     $definition->setHelp('Import command for WXR files generated by Wordpress');
     $definition->addArgument('file', CommandDefinition::REQUIRED, 'Path to WXR file');
     $definition->addOption('dry-run', null, null);
     $definition->addOption('post-layout', null, CommandDefinition::VALUE_REQUIRED, 'Layout for post items');
     $definition->addOption('fetch-images', null, null, 'Fetch images used by the Wordpress blog');
     $definition->addOption('not-replace-urls', null, null, 'Do not replace old Wordpress URLs to the new Spress path');
     $definition->addOption('assets-dir', null, CommandDefinition::VALUE_REQUIRED, 'Relative directory to content folder for storing the fetched images', 'assets');
     return $definition;
 }
All Usage Examples Of Yosymfony\Spress\Plugin\CommandDefinition::addOption