Returns a command instance based on the command name requested.

@param string $command The name of the command.

@return PortaText\Command\ICommand
@throws InvalidArgumentException
321267
public function get($command)
    {
        $className = ucfirst($command);
        $className = "PortaText\\Command\\Api\\$className";
        if (!class_exists($className)) {
            throw new \InvalidArgumentException(
                "Command $command does not exist"
            );
        }
        return new $className();
    }
774847
public function resolve(Command $command)
    {
        $commandName = get_class($command);

        // Find the CommandHandler if it has been manually defined using pushHandler()
        foreach ($this->handlers as $handlerCommand => $handler) {
            if ($handlerCommand == $commandName) {
                return $handler;
            }
        }

        // If the Command also implements CommandHandler, then it can handle() itself
        if ($command instanceof CommandHandler) {
            return $command;
        }

        // Try and guess the handler's name in the same namespace with suffix "Handler"
        $class = $commandName . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        // Try and guess the handler's name in nested "Handlers" namespace with suffix "Handler"
        $classParts = explode('\\', $commandName);
        $commandNameWithoutNamespace = array_pop($classParts);
        $class = implode('\\', $classParts) . '\\Handlers\\' . $commandNameWithoutNamespace . 'Handler';
        if (class_exists($class)) {
            return $this->container->make($class);
        }

        throw new UnresolvableCommandHandlerException('Could not resolve a handler for [' . get_class($command) . ']');
    }
923478
public static function forCommand($command)
    {
        $type =  is_object($command) ? get_class($command) : gettype($command);

        $exception = new static('Could not determine command name of ' . $type);
        $exception->command = $command;

        return $exception;
    }
562498
public function resolve($command)
    {
        $commandInstance = $this->di->get($command);

        return $this->add($commandInstance);
    }
108566
public static function validateCommandName($name)
    {
        $name = trim($name);

        if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
            throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
        }

        return $name;
    }
741432
public function command($name, $command)
    {
        /** @var AbstractCommand $command */
        $command = is_string($command) ? new $command() : $command;
        $command->setContainer($this->container);

        // Set name
        $namespace = $this->config->get('application_name');
        $name = $name ?: $command->getName();
        $command->setName($namespace.':'.$name);

        $this->console->add($command);

        return $command;
    }
862620
public function resolveCommand($command)
    {
        if ($fullPaths = $this->findWhere($command)) {
            $fullPaths = preg_split('/[\r\n]/', trim($fullPaths));
            $command = end($fullPaths);
        }

        return $command;
    }
60331
public function handle(CommandInterface $command)
    {
        if (!$this->supports(get_class($command))) {
            throw new InvalidArgumentException(
                sprintf(
                    'The command must be an instance of "%s". "%s" given.',
                    $this->getSupportedCommandClassName(),
                    get_class($command)
                )
            );
        }

        return $this->execute($command);
    }
770881
public function prepareCommand(CommandInterface $command)
    {
        $request = parent::prepareCommand($command);
        $request->setHeader('Authorization ','Bearer '. $this->prepareAccessToken());
        return $request;
    }
258226
protected function executeCmd($command)
    {
        $process = new $this->processClass($command);
        $process->run();

        if (false === $process->isSuccessful() && strlen($process->getErrorOutput()) > 0) {
            throw new \RuntimeException($process->getErrorOutput());
        }

        return $process->getOutput();
    }
641031
public function Rcon( $Command )
		{
			if( !$this->Connected )
			{
				throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
			}
			
			if( $this->Rcon === null )
			{
				throw new SocketException( 'You must set a RCON password before trying to execute a RCON command.', SocketException::NOT_CONNECTED );
			}
			
			return $this->Rcon->Command( $Command );
		}
841212
public function invoke(IDefinition $definition, $command) {
        $handler = $definition->getHandler();

        if ($this->isValidHandlerClass($handler)) {
            $handler = $this->createHandler($handler);
        }

        if ($this->isValidHandler($handler)) {
            return $this->invokeHandler($handler, $command);
        }

        throw new InvalidCommandHandlerException(s(
            'Handler "%s" must implement method "handle($command)".',
            is_string($handler) ? $handler : get_type($handler)
        ));
    }
103951
public function get($name)
    {
        switch ($name) {
            case '_':
                return $this->returnValue;

            case '_e':
                if (isset($this->lastException)) {
                    return $this->lastException;
                }
                break;

            case '__out':
                if (isset($this->lastStdout)) {
                    return $this->lastStdout;
                }
                break;

            case 'this':
                if (isset($this->boundObject)) {
                    return $this->boundObject;
                }
                break;

            case '__function':
            case '__method':
            case '__class':
            case '__namespace':
            case '__file':
            case '__line':
            case '__dir':
                if (\array_key_exists($name, $this->commandScopeVariables)) {
                    return $this->commandScopeVariables[$name];
                }
                break;

            default:
                if (\array_key_exists($name, $this->scopeVariables)) {
                    return $this->scopeVariables[$name];
                }
                break;
        }

        throw new \InvalidArgumentException('Unknown variable: $' . $name);
    }
255642
protected function mapInputToCommand($command, array $input)
    {
        $dependencies = [];

        $class = new ReflectionClass($command);

        foreach ($class->getConstructor()->getParameters() as $parameter)
        {
            $name = $parameter->getName();

            if (array_key_exists($name, $input))
            {
                $dependencies[] = $input[$name];
            }
            elseif ($parameter->isDefaultValueAvailable())
            {
                $dependencies[] = $parameter->getDefaultValue();
            }
            else
            {
                throw new InvalidArgumentException("Unable to map input to command: {$name}");
            }
        }

        return $class->newInstanceArgs($dependencies);
    }
610118
public function getCommand($name, array $args = [])
    {
        if (!$this->description->hasOperation($name)) {
            $name = ucfirst($name);
            if (!$this->description->hasOperation($name)) {
                throw new \InvalidArgumentException(
                    "No operation found named {$name}"
                );
            }
        }

        // Merge in default command options
        $args += $this->getConfig('defaults');

        return parent::getCommand($name, $args);
    }
885290
public function getCommand(string $name): AbstractCommand
	{
		if (!isset($this->commands[$name]) && !isset($this->aliases[$name]))
		{
			throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));
		}

		return $this->commands[$name] ?? $this->aliases[$name];
	}
34142
private function getCommandLabel(CommandInterface $command)
    {
        if (null === $label = $command->getLabel()) {
            $label = $command->getName();
        }

        $label = $this->translate($label);

        return \is_array($label) ? $label[0] : $label;
    }