Easyswoole源碼分析-7-help

介紹

所有command類都實現(xiàn)了CommandInterface接口

interface CommandInterface
{
    public function commandName():string;
    public function exec(array $args):?string ;
    public function help(array $args):?string ;
}

分析

CommandRunner類里面當輸入不存在的command時,會默認為help

function run(array $args):?string 
{
       ···
        if(!CommandContainer::getInstance()->get($command)){
            $command = 'help';
        }
       ···
}

help類

class Help implements CommandInterface
{

    public function commandName(): string
    {
        // TODO: Implement commandName() method.
        return 'help';
    }

    public function exec(array $args): ?string
    {
        // TODO: Implement exec() method.
        // 如果沒有任何command,則直接調(diào)用本類的help方法
        if (!isset($args[0])) {
            return $this->help($args);
        } else {
            $actionName = $args[0];
            array_shift($args);
            // 獲取相應命令的對象
            $call = CommandContainer::getInstance()->get($actionName);
            // 是否實現(xiàn)了CommandInterface接口
            if ($call instanceof CommandInterface) {
                // 執(zhí)行相應command類的help方法
                return $call->help($args);
            } else {
                return "no help message for command {$actionName} was found";
            }
        }
    }

    public function help(array $args): ?string
    {
        // TODO: Implement help() method.
        // 獲取所有command
        $allCommand = implode(PHP_EOL, CommandContainer::getInstance()->getCommandList());
        // 展示es log
        $logo = Utility::easySwooleLog();
        return $logo.<<<HELP
Welcome To EASYSWOOLE Command Console!
Usage: php easyswoole [command] [arg]
Get help : php easyswoole help [command]
Current Register Command:
{$allCommand}
HELP;
    }
}
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 一、Python簡介和環(huán)境搭建以及pip的安裝 4課時實驗課主要內(nèi)容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 6,319評論 0 10
  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,701評論 0 5
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,626評論 1 32
  • 夢涯的感悟 相對于無窮無盡的物質(zhì)能量世界來說,我們看得到的感知得到的宇宙就象一個...
    智慧啟蒙閱讀 311評論 0 0
  • 他朝一旁的她深情的看了一眼,而后手呈喇叭狀,向著遠處大聲喊了一句,“我喜歡你。” 遠山似沒聽到這句話,他等待了好半...
    白祁藝love閱讀 405評論 0 0

友情鏈接更多精彩內(nèi)容