[英]how to debug golang cobra cli app in vscode
I have a golang cobra cli app.我有一个 golang cobra cli 应用程序。 have configured my vscode for debugging.
已经配置了我的 vscode 进行调试。 I want to debug a specific command using vscode for my application.
我想使用 vscode 为我的应用程序调试特定命令。
I am using this launch.json我正在使用这个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.如果我选择 main.go 并开始调试,它只会打印我的命令的帮助。 How can I debug a particular cli subcommand in vscode?
如何在 vscode 中调试特定的 cli 子命令? Like say abc create or abc version
就像说 abc 创建或 abc 版本
If I select a subcommand package and then debug it says : Failed to launch :could not launch process:not an executalbe file如果我选择一个子命令包然后调试它说:无法启动:无法启动进程:不是可执行文件
You can configure the VSCode launch configuration to pass arguments using:您可以配置 VSCode 启动配置以使用以下方法传递参数:
{
"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.请注意,您可能更喜欢在
program
字段中写入主 go 文件的路径,以便无论您当前在哪个文件上都可以运行/调试。
Reference:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.