英文:
how to debug golang cobra cli app in vscode
问题
我有一个使用golang cobra cli的应用程序。我已经配置了我的vscode进行调试。我想使用vscode调试我的应用程序中的特定命令。
我正在使用以下的launch.json配置:
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}"
}
如果我选择main.go并开始调试,它只会打印出我的命令的帮助信息。我如何在vscode中调试特定的cli子命令?比如说abc create或abc version。
如果我选择一个子命令package并进行调试,它会显示:启动失败:无法启动进程:不是可执行文件。
英文:
I have a golang cobra cli app. have configured my vscode for debugging. I want to debug a specific command using vscode for my application.
I am using this launch.json
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}"
}
If I select main.go and start debugging it just prints the help for my command. How can I debug a particular cli subcommand in vscode? Like say abc create or abc version
If I select a subcommand package and then debug it says : Failed to launch :could not launch process:not an executalbe file
答案1
得分: 4
你可以配置VSCode的启动配置来传递参数,示例如下:
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}",
"args": ["arg1", ...]
}
请注意,你可能更喜欢在program
字段中写入你的主要Go文件的路径,这样无论你当前在哪个文件上,都可以运行/调试。
参考链接:
- launch.json: https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes
- VSCode变量: https://code.visualstudio.com/docs/editor/variables-reference
英文:
You can configure the VSCode launch configuration to pass arguments using:
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${fileDirname}"
"args": ["arg1", ...]
}
Note that you may prefer to write the path to your main go file in the program
field so that you can run/debug no matter what file you are currently on.
Reference:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论