2017-08-29 67 views
0

我試圖通過使用VS代碼的簡單的CRUD節點模塊運行。與代碼節點調試命令

模塊的簡化版本是這樣的:

const getAll =() => { 
    // return all elements 
} 

const saveElement = element => { 
    // takes an object and goes through it and saves it 
} 

const removeElement = id => { 
    // deletes the element with the passed id or returns false 
} 

const readElement = id => { 
    // returns the element from the data 
} 

我使用yargs以獲取應用程序的參數,而且我用命令來調用每一個方法,像這樣

node app.js remove --id="123456789" 

在VS代碼的launch.json看起來是這樣的:

{ 
    "version": "0.2.0", 
    "configurations": [  
    { 
     "type": "node", 
     "request": "launch", 
     "name": "Test Remove", 
     "program": "${workspaceRoot}/app.js", 
     "args": [ 
     "--id='123456789'" 
     ] 
    } 
    ] 
} 

什麼心中已經e無法做的是將特定的remove,add,list,read命令添加到調試器中以檢查這些方法,因爲如果沒有那些應用程序只與參數一起運行,並且它會返回一個我添加的日誌,指出傳遞的命令無法識別。

我查看了VS Code文檔,但是我沒有發現任何與我正在嘗試做的事情有關的東西。

回答

1

好吧。其實很簡單。只需在args陣列中傳遞該模塊的特定命令即可。唯一需要注意的是數組中的順序必須與CLI中使用的順序相同。所以,如果這個想法是運行這個命令:

node app.js remove --id="123456789" 

launch.json對象應該是這樣的:

{ 
    "version": "0.2.0", 
    "configurations": [  
    { 
     "type": "node", 
     "request": "launch", 
     "name": "Test Remove", 
     "program": "${workspaceRoot}/app.js", 
     "args": [ 
     "remove", 
     "--id=123456789" 
     ] 
    } 
    ] 
} 

更改args陣列內的順序將導致不必要的行爲。