Callback for selecting the handler that should be run.

@param Args    $args    The console arguments.
@param IO      $io      The I/O.
@param Command $command The handled command.

@return string The name of the handler to run.
168062
public function getHandlerToRun(Args $args, IO $io, Command $command)
    {
        $rawArgs = $args->getRawArgs();

        // The raw arguments should always be available, but check anyway
        if (!$rawArgs) {
            return 'text';
        }

        // If "-h" is given, always print the short text usage
        if ($rawArgs->hasToken('-h')) {
            return 'text';
        }

        // Check if any of the options is set
        foreach ($this->getRegisteredNames() as $handlerName) {
            if ($rawArgs->hasToken('--'.$handlerName)) {
                return $handlerName;
            }
        }

        // No format option is set, "-h" is not set
        // If a command is given or if "--help" is set, display the manual
        if ($rawArgs->hasToken('--help')) {
            // Return "man" if the binary is available and the man page exists
            // The process launcher must be supported on the system
            $manPage = $this->getManPage($command->getApplication(), $args);

            if (file_exists($manPage) && $this->processLauncher->isSupported()) {
                if (!$this->manBinary) {
                    $this->manBinary = $this->executableFinder->find('man');
                }

                if ($this->manBinary) {
                    return 'man';
                }
            }

            // Return "ascii-doc" if the AsciiDoc page exists
            $asciiDocPage = $this->getAsciiDocPage($command->getApplication(), $args);

            if (file_exists($asciiDocPage)) {
                return 'ascii-doc';
            }
        }

        // No command, no option -> display command list as text
        return 'text';
    }
1189142
public function initialize($args, Cli $command)
    {
        // Set command description
        $command->set_description($this->description);
        // Every single command should have help, right?
        $command->add_arg('help', [
            'prefix'      => 'h',
            'longPrefix'  => 'help',
            'description' => Cli::lang('console_display_help'),
            'noValue'     => true
        ]);

        // Register command arguments
        $this->register($command);

        try {
            // Parse the arguments
            $command->parse_arg($args);

            // If ask for help
            if ($command->get_arg('help') !== false) {
                return $command->usage([], $this->name);
            }

            // Execute actual arguments
            return $this->execute($command);
        } catch (\Exception $e) {
            $executed = false;
            return EXIT_USER_INPUT;
        }
    }
1250075
public static function main(array $argv = [], $command = null)
    {
        $code = 0;

        $output = new ConsoleOutput();
        $input  = new ArgvInput();

        try {
            $c = static::createCli();

            array_shift($argv);

            if (null !== $command) {
                array_unshift($argv, $command);
            }

            $c->run($input, $output, $argv);
        } catch (\Exception $e) {
            if ('true' !== getenv('DEV_QUIET')) {
                $output->writeln(sprintf('<error>Error #%d: %s</error>', $e->getCode(), $e->getMessage()));
            }

            $code = ($e->getCode() > 0 && $e->getCode() < 255) ? $e->getCode() : 255;
        }

        return $code;
    }
1089423
public function run(Command $command, array $args) : int
    {
        $programName = basename(array_shift($args));

        $arg = current($args);

        if ($arg === '--help') {
            $this->printUsage($command, $programName);
            return 0;
        }

        if ($arg === '--version') {
            $this->printVersion($command);
            return 0;
        }

        try {
            $changeSet = $command->createChangeSet($args);
        } catch (BadUsage $e) {
            $this->printUsage($command, $programName);
            return 1;
        }

        $loader = new ProjectLoader(getcwd());
        $loader->registerClassLoader();

        $config = $loader->getPhpCodeSnifferConfiguration();

        try {
            if ($config !== null) {
                foreach ($config as $key => $value) {
                    Config::setConfigData($key, $value, true);
                }
            }

            // pass configuration using CLI arguments to override what's defined in the rule set
            $config = new Config(array_merge($args, ['--no-cache']));
            $runner = new Runner($config);

            return $runner->run($changeSet);
        } catch (DeepExitException $e) {
            echo $e->getMessage();
            return $e->getCode();
        }
    }
618911
protected function processCommand($command = '', $argument = '')
    {
        switch ($command) {
            case 'help':
                $this->writeln('
Debug console for phpDaemon.
Allowed commands:

help	eval	exit
');
                break;
            case 'ping':
                $this->writeln('pong');
                break;
            case 'eval':
                ob_start();
                eval($argument);
                $out = ob_get_contents();
                ob_end_clean();
                $this->writeln($out);
                break;
            default:
                $this->writeln('Unknown command "' . $command . '".
Type "help" to get the list of allowed commands.');
        }
    }
237813
protected function setOutputLevel(Arguments $args, ConsoleIo $io)
    {
        $io->setLoggers(ConsoleIo::NORMAL);
        if ($args->getOption('quiet')) {
            $io->level(ConsoleIo::QUIET);
            $io->setLoggers(ConsoleIo::QUIET);
        }
        if ($args->getOption('verbose')) {
            $io->level(ConsoleIo::VERBOSE);
            $io->setLoggers(ConsoleIo::VERBOSE);
        }
    }
896584
public function command($command, $args = [], $id = null)
    {
        $target = Router::getInstance()->getTarget($command);
        $fn = function () use ($target) {
            return $target->run();
        };

        return $this->call($fn, $args, $id);
    }
709827
public function executeByPath($arguments, array $options = [], IOInterface $io = null)
    {
        $io = $io ?: clone $this->io;

        // Path
        if (is_string($arguments)) {
            $arguments = str_replace('/', ' ', $arguments);
            $arguments = array_filter(explode(' ', $arguments), 'strlen');
        }

        $io->setArguments($arguments);

        // Options
        foreach ($options as $key => $value) {
            $io->setOption($key, $value);
        }

        return $this->getRootCommand()->setIO($io)->execute();
    }
869664
public function beforeCommand(Event $event, Command $command)
    {
        $parameters = $command->parseParameters([], ['h' => 'help']);

        if (
            count($parameters) < ($command->getRequiredParams() + 1) ||
            $command->isReceivedOption(['help', 'h', '?']) ||
            in_array($command->getOption(1), ['help', 'h', '?'])
        ) {
            $command->getHelp();

            return false;
        }

        if( !defined('BASE_PATH') ) {
            throw new CommandsException('Commands need a BASE_PATH constant defined.');
        }

        if ($command->canBeExternal() == false) {
            $path = $command->getOption('directory');
            if (!file_exists($path.'.phalcon')) {
                throw new CommandsException('This command should be invoked inside a Phalcon project directory.');
            }
        }

        return true;
    }
490203
public function getCommand($name, array $args = array()) {
    /*if($name != 'oauth') {
		  $this->checkAuth();
    }*/

    $command = parent::getCommand($name, $args);
    $this->command_history[] = $command;
		return $command;
	}
1253591
public function handleList(Args $args, IO $io)
    {
        $moduleNames = ArgsUtil::getModuleNames($args, $this->modules);
        $states = $this->getPathMappingStates($args);

        $printState = count($states) > 1;
        $printModuleName = count($moduleNames) > 1;
        $printHeaders = $printState || $printModuleName;
        $printAdvice = true;
        $indentation = ($printState && $printModuleName) ? 8
            : ($printState || $printModuleName ? 4 : 0);

        foreach ($states as $state) {
            $statePrinted = !$printState;

            if (PathMappingState::CONFLICT === $state) {
                $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::in($moduleNames)))
                    ->andMethod('getState', Expr::same($state));

                $mappings = $this->repoManager->findPathMappings($expr);

                if (!$mappings) {
                    continue;
                }

                $printAdvice = false;

                if ($printState) {
                    $this->printPathMappingStateHeader($io, $state);
                }

                $this->printConflictTable($io, $mappings, $printState ? 4 : 0);

                if ($printHeaders) {
                    $io->writeLine('');
                }

                continue;
            }

            foreach ($moduleNames as $moduleName) {
                $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName)))
                    ->andMethod('getState', Expr::same($state));

                $mappings = $this->repoManager->findPathMappings($expr);

                if (!$mappings) {
                    continue;
                }

                $printAdvice = false;

                if (!$statePrinted) {
                    $this->printPathMappingStateHeader($io, $state);
                    $statePrinted = true;
                }

                if ($printModuleName) {
                    $prefix = $printState ? '    ' : '';
                    $io->writeLine(sprintf('%sModule: %s', $prefix, $moduleName));
                    $io->writeLine('');
                }

                $this->printMappingTable($io, $mappings, $indentation, PathMappingState::ENABLED === $state);

                if ($printHeaders) {
                    $io->writeLine('');
                }
            }
        }

        if ($printAdvice) {
            $io->writeLine('No path mappings. Use "puli map <path> <file>" to map a Puli path to a file or directory.');
        }

        return 0;
    }
435287
public function execute(Arguments $args, ConsoleIo $io)
    {
        $io->out(Configure::version());

        return static::CODE_SUCCESS;
    }
1120516
protected function executeCommand(Command $command, array $arguments, OutputInterface $output)
    {
        $output = clone $output;
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $output->setVerbosity($output->getVerbosity());
        } else {
            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        }

        return $command->run(new ArrayInput($arguments), $output);
    }
470124
public function callSilent($command, array $arguments = []) {
		$instance = $this->getApplication()->find($command);
		$arguments['command'] = $command;

		return $instance->run(new ArrayInput($arguments), new NullOutput);
	}
1026245
public function callHandler(array $command, $method, $args = array())
    {
        try {
            $handlers = $this->getHandlers();
            return Handler::call($handlers, $command['command_id'], $method, $args);
        } catch (Exception $ex) {
            return $ex->getMessage();
        }
    }
1311479
public void execRun(String command) throws IOException, PHPException {
	    writeCommand("R" + command);
	    phpConsoleLogger.write(command);
		String readLine = readLine();
        phpConsoleLogger.read(readLine);
		
	}
1344283
public function processArgs( ICommand &$command, $args )
    {
        $i = 0;

        $ops = array_slice( $args, 2 );

        while ( $i < count( $ops ) )
        {
            $o = $ops[ $i ];

            if ( Option::isShortCode( $o ) || Option::isLongCode( $o ) )
            {
                $option = Command::getOption( $command, $o );

                if ( $option->isRequired )
                {
                    $i++;

                    if ( !Util::validIndex( $i, $ops ) )
                    {
                        throw new CommandException( 'Missing argument for option: ' . $o );
                    }

                    Option::setRequiredValue( $option, $ops[ $i ] );
                }

                if ( $option->isOptional )
                {
                    $value = NULL;

                    if ( $option->type === Type::BOOLEAN )
                    {
                        $value = TRUE;
                    }
                    else
                    {
                        $i++;

                        $value = $ops[ $i ];
                    }

                    if ( Util::validIndex( $i, $ops ) )
                    {
                        Option::setOptionalValue( $option, $value );
                    }
                    else if ( is_bool( $value ) )
                    {
                        Option::setOptionalValue( $option, $value );
                    }
                }
            }

            $i++;
        }
    }