Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用节点wp cli运行自定义wp cli命令?_Node.js_Wordpress_Wp Cli - Fatal编程技术网

Node.js 如何使用节点wp cli运行自定义wp cli命令?

Node.js 如何使用节点wp cli运行自定义wp cli命令?,node.js,wordpress,wp-cli,Node.js,Wordpress,Wp Cli,我正在使用从Node.js运行WP cli命令。所有内置的WP-cli命令都工作得很好,但我在尝试运行自定义WP-cli命令时遇到了问题 是否有方法从节点WP Cli运行自定义WP Cli命令WP MyRegisteredCommand子命令?比如: WP.MyRegisteredCommand.SubCommand(function(err,res){ //get response console.log(res); }); 这是相对容易的,但需要一些调整 Node wp cli使用

我正在使用从Node.js运行WP cli命令。所有内置的WP-cli命令都工作得很好,但我在尝试运行自定义WP-cli命令时遇到了问题

是否有方法从节点WP Cli运行自定义WP Cli命令
WP MyRegisteredCommand子命令
?比如:

WP.MyRegisteredCommand.SubCommand(function(err,res){ //get response
    console.log(res);
});

这是相对容易的,但需要一些调整

Node wp cli使用
wp cli cmd dump
标识可用命令,但此命令在加载WordPress之前运行,因此它将仅识别内置命令

简而言之,调整:

  • 请参见
    WP.js
    ,行
    schema(函数(err,schema){…
    。您需要了解
    schema
    的结构,因此只需运行一些内置命令并在此处放置断点
  • 按照上面的模式结构,为您的命令实现模式。它将如下所示:

    my_commands.js

    var schema = {
        mycmd: {
            mysubcmd: {
                args: [ {
                    arg: 'arg1',
                    required: true,
                    type: 'args'
                } ],
                endpoint: true,
                options: {
                    opt1: {
                        required: true,
                        type: 'param'
                    },
                    flag1: {
                        required: false,
                        type: 'flag'
                    },
                }
            },
            use: 'wp mycmd mysubcmd'
        }
    }
    
    module.exports.schema = schema;
    
    var mySchema = require('my_commands.js').schema;
    
    ...
    
    schema(function(err,schema){
    
        schema = _.merge(schema, mySchema); // this line added
    
        var toMerge = function mapSchema(schema){
    
  • 修改WP.js

    var schema = {
        mycmd: {
            mysubcmd: {
                args: [ {
                    arg: 'arg1',
                    required: true,
                    type: 'args'
                } ],
                endpoint: true,
                options: {
                    opt1: {
                        required: true,
                        type: 'param'
                    },
                    flag1: {
                        required: false,
                        type: 'flag'
                    },
                }
            },
            use: 'wp mycmd mysubcmd'
        }
    }
    
    module.exports.schema = schema;
    
    var mySchema = require('my_commands.js').schema;
    
    ...
    
    schema(function(err,schema){
    
        schema = _.merge(schema, mySchema); // this line added
    
        var toMerge = function mapSchema(schema){
    

    • 这相对容易,但需要一些调整

      Node wp cli使用
      wp cli cmd dump
      标识可用命令,但此命令在加载WordPress之前运行,因此它将仅识别内置命令

      简而言之,调整:

      • 请参见
        WP.js
        ,行
        schema(函数(err,schema){…
        。您需要了解
        schema
        的结构,因此只需运行一些内置命令并在此处放置断点
      • 按照上面的模式结构,为您的命令实现模式。它将如下所示:

        my_commands.js

        var schema = {
            mycmd: {
                mysubcmd: {
                    args: [ {
                        arg: 'arg1',
                        required: true,
                        type: 'args'
                    } ],
                    endpoint: true,
                    options: {
                        opt1: {
                            required: true,
                            type: 'param'
                        },
                        flag1: {
                            required: false,
                            type: 'flag'
                        },
                    }
                },
                use: 'wp mycmd mysubcmd'
            }
        }
        
        module.exports.schema = schema;
        
        var mySchema = require('my_commands.js').schema;
        
        ...
        
        schema(function(err,schema){
        
            schema = _.merge(schema, mySchema); // this line added
        
            var toMerge = function mapSchema(schema){
        
      • 修改WP.js

        var schema = {
            mycmd: {
                mysubcmd: {
                    args: [ {
                        arg: 'arg1',
                        required: true,
                        type: 'args'
                    } ],
                    endpoint: true,
                    options: {
                        opt1: {
                            required: true,
                            type: 'param'
                        },
                        flag1: {
                            required: false,
                            type: 'flag'
                        },
                    }
                },
                use: 'wp mycmd mysubcmd'
            }
        }
        
        module.exports.schema = schema;
        
        var mySchema = require('my_commands.js').schema;
        
        ...
        
        schema(function(err,schema){
        
            schema = _.merge(schema, mySchema); // this line added
        
            var toMerge = function mapSchema(schema){