• cakephp控制台脚本Console/shell使用


    配置shell脚本的参数arg和选项opt

    官网上的方式是在shell中重写 getOptionParser() 。

    public function getOptionParser() {
        $parser = parent::getOptionParser();
        $parser->addArgument('type', array(
            'help' => 'Either a full path or type of class.', 'required'=>true
        ))->addArgument('className', array(
            'help' => 'A CakePHP core class name (e.g: Component, HtmlHelper).'
        ))->addOption('method', array(
            'short' => 'm',
            'help' => __('The specific method you want help on.')
        ))->description(__('Lookup doc block comments for classes in CakePHP.'));
        return $parser;
    }
    

    使用 docker exec -it dnmp-php56 /ubox/apps/charts/app/Console/cake test --h 显示帮助,不执行脚本
    运行结果如下:

    Lookup doc block comments for classes in CakePHP.
    
    Usage:
    cake test [-h] [-v] [-q] [-h] [<type>] [<className>]
    
    Options:
    
    --help, -h     Display this help.
    --verbose, -v  Enable verbose output.
    --quiet, -q    Enable quiet output.
    --method, -m  The specific method you want help on.
    
    Arguments:
    
    type  Either a full path or type of class. (optional)
    className  A CakePHP core class name (e.g: Component, HtmlHelper). (optional)
    

    Arguments 参数是指定位置顺序的,而 Options 和位置无关。

  • 相关阅读:
    Java 线程终止
    Android Jetpack架构之ProcessLifeCycleOwner
    Android Jetpack架构之LifecycleService
    Android Jetpack架构之Lifecycle
    Android Jetpack架构
    深入理解JNI技术
    Java虚拟机类加载器机制
    Java HashMap、HashTable、ConcurrentHashMap区别
    Java内存分配策略
    Java 方法分派
  • 原文地址:https://www.cnblogs.com/aworkstory/p/12624863.html
Copyright © 2020-2023  润新知