Webmozart\Console\Api\Config\OptionCommandConfig::setShortName PHP Méthode

setShortName() public méthode

The short name must consist of a single letter. The short name is preceded by a single dash "-" when calling the command: $ server -d localhost In the example above, "d" is the short name of the "server --delete" command.
public setShortName ( string $shortName ) : static
$shortName string The short option name.
Résultat static The current instance.
    public function setShortName($shortName)
    {
        if (null !== $shortName) {
            Assert::string($shortName, 'The short command name must be a string or null. Got: %s');
            Assert::notEmpty($shortName, 'The short command name must not be empty.');
            Assert::regex($shortName, '~^[a-zA-Z]$~', 'The short command name must contain a single letter. Got: %s');
        }
        // Reset short name preference when unsetting the short name
        if (null === $shortName && false === $this->longNamePreferred) {
            $this->longNamePreferred = null;
        }
        $this->shortName = $shortName;
        return $this;
    }

Usage Example

 public function testBuildAnonymousArgsFormat()
 {
     $baseFormat = new ArgsFormat();
     $this->config->setName('command');
     $this->config->setShortName('c');
     $this->config->setAliases(array('alias1', 'alias2'));
     $this->config->addOption('option');
     $this->config->addArgument('argument');
     $this->config->markAnonymous();
     $expected = ArgsFormat::build($baseFormat)->addArgument(new Argument('argument'))->addOption(new Option('option'))->getFormat();
     $this->assertEquals($expected, $this->config->buildArgsFormat($baseFormat));
 }