AbstractCommander::addCommandOption

Add command option.

@param string $optionName
@param string $optionDescription
@param string $optionShortcut

@return $this;
777630
public function addCommandOption($optionName, $optionDescription, $optionShortcut = null)
    {
        $optionShortcut = empty($optionShortcut)
            ? '-' . substr($optionName, 0, 1)
            : '-' . rtrim($optionShortcut);

        $this->commandOptions[ $optionName ] = [
            'shortcut'    => $optionShortcut,
            'description' => $optionDescription,
        ];
    }
1141914
public function addOption(OptionInterface $option, $name = null)
    {
        $this->options[$name ?: $option->getName()] = $option;
        if ($option instanceof OptionRegistryAwareInterface) {
            $option->setOptionRegistry($this);
        }

        return $this;
    }
254165
protected function setOptionIfNotSet(array $options, $optionName, $optionDefaultValue)
    {
        if (!isset($options[$optionName])) {
            $options[$optionName] = $optionDefaultValue;
        }

        return $options;
    }
547018
protected function createCommand($commandName, array $commandDca)
    {

        $command = $this->createCommandInstance($commandName, $commandDca);
        $command->setName($commandName);

        $parameters = $command->getParameters();

        if (isset($commandDca['href'])) {
            \parse_str($commandDca['href'], $queryParameters);
            foreach ($queryParameters as $name => $value) {
                $parameters[$name] = $value;
            }
            unset($commandDca['href']);
        }

        if (isset($commandDca['parameters'])) {
            foreach ($commandDca['parameters'] as $name => $value) {
                $parameters[$name] = $value;
            }
            unset($commandDca['parameters']);
        }

        if (isset($commandDca['label'])) {
            $lang = $commandDca['label'];

            if (\is_array($lang)) {
                $label       = \reset($lang);
                $description = \next($lang);

                $command->setDescription($description);
            } else {
                $label = $lang;
            }

            $command->setLabel($label);

            unset($commandDca['label']);
        }

        if (isset($commandDca['description'])) {
            $command->setDescription($commandDca['description']);

            unset($commandDca['description']);
        }

        // Callback is transformed into event in parseCallbacks().
        unset($commandDca['button_callback']);

        if (\count($commandDca)) {
            $extra = $command->getExtra();

            foreach ($commandDca as $name => $value) {
                $extra[$name] = $value;
            }
        }

        return $command;
    }
411609
public function addCommand(string $name, $handler = null, $option = null): self
    {
        return $this->command($name, $handler, $option);
    }
914597
public function addOption(OptionInterface $option)
    {
        if (!$this->hasOption($option)) {
            $this->options->add($option);
        }

        return $this;
    }
693625
protected function createCommandInstance($commandName, array &$commandDca)
    {
        switch ($commandName) {
            case 'cut':
                return new CutCommand();

            case 'copy':
            case 'deepcopy':
                return new CopyCommand();

            case 'all':
                return new SelectCommand();

            case 'toggle':
                $command = new ToggleCommand();

                if (isset($commandDca['toggleProperty'])) {
                    $command->setToggleProperty($commandDca['toggleProperty']);
                    unset($commandDca['toggleProperty']);
                } else {
                    // Implicit fallback to "published" as in Contao core.
                    $command->setToggleProperty('published');
                }

                if (isset($commandDca['toggleInverse'])) {
                    $command->setInverse($commandDca['toggleInverse']);
                    unset($commandDca['toggleInverse']);
                }

                return $command;
            default:
        }
        return new Command();
    }
641652
private static void addShortcut(StringBuilder sb, Set<String> shortcuts) {
        if (sb.length() > 0) {
            String shortcut = validateShortcut(sb.toString());
            
            if (shortcut != null) {
                shortcuts.add(shortcut);
            }
            
            sb.delete(0, sb.length());
        }
    }
965582
public function hardwareOption($option, $additionalOption = null)
    {
        $command = new Command\Stored\HardwareOptionCommand($option, $additionalOption);
        $this->getComposite()->addCommand($command);
        return $this;
    }
713955
public static function setOption($optionName = "", $optionValue = "") {
		
		if (empty($optionName) || empty($optionValue)) {
			return false;
		}
		
		$arrayFinder = new ArrayFinder(self::$options);
		$arrayFinder->set($optionName, $optionValue);
		self::$options = $arrayFinder->get();
		
	}
754257
protected function addArgument(string $name, string $desc, string $default_value = '', int $position = null, bool $is_require = false) : void
    {
        if($position === null){
            $position   = count($this->arguments());
        }
        $CommandArgument    = new CommandArgument($name, $desc, $default_value, $position, $is_require);
        $this->arguments()->append($CommandArgument);
    }
19135
public static function setOptionLink($optionName,$optionValue) {

		if (!isset(self::$store["link"])) {
			self::$store["link"] = array();
		}

		self::$store["link"][$optionName] = $optionValue;

	}
565579
public function addCommand(
        string $name,
        string $description,
        array $operands = null,
        array $options = null,
        array $parameters = null
    ): ShellBuilder {
        $definition = new Definition();
        foreach ($operands ?? [] as $operand) {
            $definition->addOperand(
                new Operand($operand['name'])
            );
        }

        foreach ($options ?? [] as $option) {
            $definition->addOption(
                new Option(
                    $option['name'],
                    $option['description'],
                    $option['short'] ?? null,
                    $option['long'] ?? null,
                    $option['flag'] ?? null,
                    $option['multiple'] ?? null
                )
            );
        }

        $this->commands[] = new Command(
            $name,
            $description,
            $definition,
            $parameters
        );

        return $this;
    }
688891
public static void addShortcutToComponent(final JComponent component, final KeyStroke keystroke,
		final String actionCommand, final Action action)
	{
		addShortcutToComponent(component, keystroke, JComponent.WHEN_IN_FOCUSED_WINDOW,
			actionCommand, action);
	}
469137
public static void addShortcutToComponent(final JComponent component, final KeyStroke keystroke,
		final int whenInFocus, final String actionCommand, final Action action)
	{
		final InputMap keyMap = new ComponentInputMap(component);
		keyMap.put(keystroke, actionCommand);
		final ActionMap actionMap = new ActionMapUIResource();
		actionMap.put(actionCommand, action);
		SwingUtilities.replaceUIActionMap(component, actionMap);
		SwingUtilities.replaceUIInputMap(component, whenInFocus, keyMap);
	}
1061191
public function addShortCut( $short, $long )
	{
		if( !isset( $this->shortcuts[$short] ) )
			$this->shortcuts[$short]	= $long;
		else
			trigger_error( "Shortcut '".$short."' is already set", E_USER_ERROR );
	}
158263
public static function addOptions(InputDefinition $definition, array $fields, $description)
    {
        foreach ($fields as $field => $type) {
            $mode = 'array' === $type
                ? InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
                : InputOption::VALUE_REQUIRED;

            if (!$definition->hasOption($field) && !$definition->hasArgument($field)) {
                $definition->addOption(new InputOption($field, null, $mode, sprintf($description, $field, $type)));
            }
        }
    }