public function format(ICommand $command) : string
    {
        $text = $command->getName() . ' ';

        // Output the options
        foreach ($command->getOptions() as $option) {
            $text .= $this->formatOption($option) . ' ';
        }

        /** @var Argument[] $requiredArguments */
        $requiredArguments = [];
        /** @var Argument[] $optionalArguments */
        $optionalArguments = [];
        /** @var Argument $arrayArgument */
        $arrayArgument = null;

        // Categorize each argument
        foreach ($command->getArguments() as $argument) {
            if ($argument->isRequired() && !$argument->isArray()) {
                $requiredArguments[] = $argument;
            } elseif ($argument->isOptional() && !$argument->isArray()) {
                $optionalArguments[] = $argument;
            }

            if ($argument->isArray()) {
                $arrayArgument = $argument;
            }
        }

        // Output the required arguments
        foreach ($requiredArguments as $argument) {
            $text .= $argument->getName() . ' ';
        }

        // Output the optional arguments
        foreach ($optionalArguments as $argument) {
            $text .= "[{$argument->getName()}] ";
        }

        // Output the array argument
        if ($arrayArgument !== null) {
            $text .= $this->formatArrayArgument($arrayArgument);
        }

        return trim($text);
    }
public function format(ICommand $command) : string
    {
        $text = $command->getName() . ' ';

        // Output the options
        foreach ($command->getOptions() as $option) {
            $text .= $this->formatOption($option) . ' ';
        }

        /** @var Argument[] $requiredArguments */
        $requiredArguments = [];
        /** @var Argument[] $optionalArguments */
        $optionalArguments = [];
        /** @var Argument $arrayArgument */
        $arrayArgument = null;

        // Categorize each argument
        foreach ($command->getArguments() as $argument) {
            if ($argument->isRequired() && !$argument->isArray()) {
                $requiredArguments[] = $argument;
            } elseif ($argument->isOptional() && !$argument->isArray()) {
                $optionalArguments[] = $argument;
            }

            if ($argument->isArray()) {
                $arrayArgument = $argument;
            }
        }

        // Output the required arguments
        foreach ($requiredArguments as $argument) {
            $text .= $argument->getName() . ' ';
        }

        // Output the optional arguments
        foreach ($optionalArguments as $argument) {
            $text .= "[{$argument->getName()}] ";
        }

        // Output the array argument
        if ($arrayArgument !== null) {
            $text .= $this->formatArrayArgument($arrayArgument);
        }

        return trim($text);
    }
public function format ( ICommand $ command ) : string { $ text = $ command -> getName ( ) . ' ' ; // Output the options foreach ( $ command -> getOptions ( ) as $ option ) { $ text .= $ this -> formatOption ( $ option ) . ' ' ; } /** @var Argument[] $requiredArguments */ $ requiredArguments = [ ] ; /** @var Argument[] $optionalArguments */ $ optionalArguments = [ ] ; /** @var Argument $arrayArgument */ $ arrayArgument = null ; // Categorize each argument foreach ( $ command -> getArguments ( ) as $ argument ) { if ( $ argument -> isRequired ( ) && ! $ argument -> isArray ( ) ) { $ requiredArguments [ ] = $ argument ; } elseif ( $ argument -> isOptional ( ) && ! $ argument -> isArray ( ) ) { $ optionalArguments [ ] = $ argument ; } if ( $ argument -> isArray ( ) ) { $ arrayArgument = $ argument ; } } // Output the required arguments foreach ( $ requiredArguments as $ argument ) { $ text .= $ argument -> getName ( ) . ' ' ; } // Output the optional arguments foreach ( $ optionalArguments as $ argument ) { $ text .= "[{$argument->getName()}] " ; } // Output the array argument if ( $ arrayArgument !== null ) { $ text .= $ this -> formatArrayArgument ( $ arrayArgument ) ; } return trim ( $ text ) ; }
Gets the command as text

@param ICommand $command The command to convert
@return string The command as text
Gets the command as text