Calls to command action.
@since 1.0.0
@since 1.0.1 Added type definition.
@since 1.0.2 Added option model.
@since 1.0.3 Fixed category option model creation.

@param array $args Action arguments.
974742
public function call($args = [])
    {
        if (count($args) == 0 || empty($args[2]))
            throw new NoticeException('Command "'.$this->key.'": Expecting an object to create (model|view|controller).');

        $object = explode(':', $args[2]);

        switch ($object[0]) {
            case 'view':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": View key name is missing.');
                $this->createView($object[1], $args);
                break;
            case 'controller':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Controller definition is missing.');
                $controller = explode('@', $object[1]);
                $this->createController($controller[0], $args);
                // Create method
                if (count($controller) > 1)
                    $this->createControllerMethod($controller[0], $controller[1]);
                break;
            case 'model':
            case 'postmodel':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Model definition is missing.');
                $this->createModel($object[1]);
                // Add type
                if (isset($args[3]))
                    $this->createModelProperty($object[1], 'type', $args[3]);
                break;
            case 'optionmodel':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Model definition is missing.');
                $this->createModel($object[1], 'OptionModel');
                // Add id
                $this->createModelProperty($object[1], 'id', isset($args[3]) ? $args[3] : uniqid());
                break;
            case 'usermodel':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Model definition is missing.');
                $this->createModel($object[1], 'UserModel');
                break;
            case 'categorymodel':
                if (!isset($object[1]) || empty($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Model definition is missing.');
                $this->createModel($object[1], 'CategoryModel');
                break;
        }
    }
634350
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        $format = isset($options['format']) ? $options['format'] : $options['f'];

        if (null !== $format) {
            Output::writeln('using format ' . $format);
        }

        $this->getManager()->printStatus($format);
    }
285224
private function call($command)
    {
        if (!in_array($command, static::COMMAND)) {
            $this->throwFailsCommand("The command '$command' not exists.", 'help');
        }

        if (!$this->arg->getParameter('action')) {
            if ($this->arg->getParameter('target') == 'help') {
                $this->help($command);

                exit(0);
            }
        }

        try {
            call_user_func_array(
                [$this, $command],
                [$this->arg->getParameter('target')]
            );
        } catch (\Exception $e) {
            echo $e->getMessage();

            exit(1);
        }
    }
719635
private function runUpdate($args)
    {
        $cmd = new UpdateCommand($this->cwd);

        return $cmd->run(array_slice($args, 1));
    }
485983
public function call($args = [])
    {
        if (count($args) == 0 || empty($args[2]))
            throw new NoticeException('Command "'.$this->key.'": Expecting a hook (action|filter|shortcode).');

        $object = explode(':', $args[2]);

        // Validations
        if (!in_array($object[0], ['action', 'filter', 'shortcode']))
            throw new NoticeException('Command "'.$this->key.'": Invalid hook. Expecting action or filter.');

        if (!isset($object[1]))
            throw new NoticeException('Command "'.$this->key.'": Expecting a hook name. i.e. add:init (where "init" would be the hook name).');

        if (count($args) == 3)
            $args[] = 'AppController@'.$object[1];

        // View or controller
        $vc = explode('@', $args[3]);
        if (count($vc) == 1) {
            $vc[] = preg_replace('/\-\./', '_', $object[1]);
            $args[3] .= '@'.$vc[1];
        }
        switch ($vc[0]) {
            case 'view':
                $this->createView($vc[1]);
                break;
            default:
                $this->createController($vc[0]);
                $this->createControllerMethod(
                    $vc[0],
                    $vc[1],
                    $this->getHookParams($object[1]),
                    (ucfirst($object[0]).' "'.$object[1].'"'."\n".'     * Wordpress hook')
                );
                break;
        }

        // Add hook to bridge
        $builder = Builder::parser($this->rootPath.'/app/Main.php');
        $builder->addVisitor(new AddMethodCallVisitor($this->getHookScope($object[1]), 'add_'.$object[0], [$object[1], $args[3]]));
        $builder->build();
    }
695458
private function runAction($action, $args)
    {
        $function = $action['function'];
        $argsNumber = $action['arguments'];

        $class = (isset($function[0])) ? $function[0] : false;
        $method = (isset($function[1])) ? $function[1] : false;

        $args = $this->getArguments($argsNumber, $args);

        if (! ($class && $method) && function_exists($function)) {
            return call_user_func($function, $args);
        } elseif ($obj = call_user_func([$class, $this->singleton])) {
            if ($obj !== false) {
                return call_user_func_array([$obj, $method], $args);
            }
        } elseif (class_exists($class)) {
            $instance = new $class;

            return call_user_func_array([$instance, $method], $args);
        }
    }
587930
public function register($arguments, $options)
    {
        $method = array_shift($arguments);

        $this->setArguments($arguments);
        $this->setOptions($options);

        if (method_exists($this, $method)) {
            try {
                return $this->app->call([$this, $method]);
            } catch (Exception $e) {
                $this->error($e->getMessage());
            }
        }

        $this->error("You have to provide command argument [$this->signature <argument>].");
    }
174872
public function listen($args = null)
    {
        if ('action' === $this->getModel()->getType()) {
            return do_action($this->getModel()->getIdentifier(), $args);
        }

        return apply_filters($this->getModel()->getIdentifier(), $args);
    }
847942
public function call($args = [])
    {
        if (count($args) == 0 || empty($args[2]))
            throw new NoticeException('Command "'.$this->key.'": Expecting a setting (version).');

        $object = explode(':', $args[2]);

        // Validations
        if (!in_array($object[0], ['version']))
            throw new NoticeException('Command "'.$this->key.'": Invalid setting. Expecting version.');

        switch ($object[0]) {
            case 'version':
                // Validate second parameter
                if ($object[0] === 'version' && !isset($object[1]))
                    throw new NoticeException('Command "'.$this->key.'": Expecting a version.');
                $this->setVersion($object[1]);
                break;
        }
    }
997680
public function execute(array $args = [], array $options = [])
    {
        $argv = $_SERVER['argv'];
        array_shift($argv);
        array_shift($argv);

        $argvString = '';
        foreach ($argv as $arg) {
            $argvString .= ($argvString ? ' ' : '').'"'.str_replace('"', '\\"', $arg).'"';
        }
        $found = null;
        foreach ($this->getConfig()->get('_shell_scripts_dirs', []) as $dir) {
            $path = sprintf('%s/%s', $dir, $this->script);
            if (!is_file($path)) {
                continue;
            }
            $found = $path;
        }
        if (null === $found) {
            throw new \RuntimeException(sprintf("Unknown shell script '%s'", $this->script), 412);
        }

        $this->executeShellCommand(sprintf('%s %s', $found, $argvString), $options);
    }
75202
protected function handleArgs(array $args) {
        $groupedArgs = $this->argumentsParser->group($args);
        list($groupedArgs, $continue) = $this->runGlobalCommands($groupedArgs);

        if ($continue === false) {
            return;
        }

        try {
            list($command, $groupedArgs) = $this->argumentsMatcher
                ->matchCommands($this->getNotGlobalCommands(), $groupedArgs);
            $command = clone $command;
            $this->runCommand($command);
        } catch (MissingCommandNameException $ex) {
            array_unshift($args, $this->getDefaultCommandName());
            $this->parseArgs($args);
        } catch (Exception $ex) {
            if ($this->getCatchErrors()) {
                $widget = new ExceptionWidget($this->input, $this->output);
                $widget->render($ex);
            } else {
                throw $ex;
            }
        }
    }
1296602
public function run(array $args)
    {
        Index::info('Usage: `cradle package <vendor/package> <command>`  - Runs a package event');
        Index::info('Usage: `cradle <vendor/package> <command>`          - Runs a package event');
        Index::info('Usage: `cradle event <event name> <json|query>`     - Runs an event');
        Index::info('Usage: `cradle <event name> <json|query>`           - Runs an event');
    }
993763
public function additionalArgs(array $args) : void
    {
        foreach ($args as $a) {
            //match --extends
            if (substr($a, 0, strlen("--extends=")) == "--extends=") {
                $this->extends = explode("=", $a);
                $this->extends = $this->extends[1];
                continue;
            }

            if ($a == "--no-factory") {
                $this->createFactory = false;
                continue;
            }

            if (substr($a, 0, strlen("--test=")) == "--test=") {
                $this->test = explode("=", $a)[1];
                continue;
            }
        }
    }
819599
public function execute(array $args = [], array $options = [])
    {
        if (!$this->evaluate($this->condition)) {
            return;
        }

        $this->command->execute($args, $options);
    }
1196254
final public function run(int $argc, array $argv)
    {
        $ar = new ArgsManager();
        $ar->getArgs($argc, $argv);
    }
495209
public function addArguments($arguments = [])
    {
        if (null !== $arguments) {
            foreach ($arguments as $argument) {
                $this->addArgument($argument);
            }
        }
    }
498002
public function create( $args, $assoc_args ) {

		$menu_id = wp_create_nav_menu( $args[0] );

		if ( is_wp_error( $menu_id ) ) {

			WP_CLI::error( $menu_id->get_error_message() );

		} else {

			if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
				WP_CLI::line( $menu_id );
			} else {
				WP_CLI::success( "Created menu {$menu_id}." );
			}
		}
	}