简体   繁体   中英

how to pass 2 or more arguments to Hubot

I'm trying to make hubot work with powershell. Hubot listens to the command (get service 'servicename' in this example), parces input and sends it to powershell.

module.exports = (robot) ->
 robot.respond /get service (.*)$/i, (msg) ->
    serviceName = msg.match[1]

    psObject = {
      serviceName: serviceName
    }

    callPowerShell = (psObject, msg) 

This code works fine with one argument, but I don't know how to pass two arguments to hubot, for example, servicename and compname (get service 'servicename' 'compname').

You should add one more brackets (.*) in respond or listen command. You can add as many as you wish, and also you can add brackets inside brackets. Just count them from the left and count them as 1st, 2nd ... and so on.

module.exports = (robot) ->
    robot.respond /get service (.*) (.*)$/i, (msg) ->
        serviceName = msg.match[1]
        paramTwo = msg.match[2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM