在调试过程中无法设置Go应用程序的参数。

huangapple go评论72阅读模式
英文:

Cannot set arguments for go app during debugging

问题

我正在尝试调试我的Goland应用程序,并且在launch.json文件中遇到了一些问题。我的应用程序应该使用参数运行:my_go_app -c path_to_config。

我的launch.json文件如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch my go app",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c /home/roman/projects/myapp/some.json"]
        }
    ]
}

但是当我调试应用程序时,我收到了以下错误:

flag provided but not defined: -c /home/roman/projects/myapp/some.json
Usage of /tmp/__debug_bin542579318:
-c string
Specify the configuration file. (default "config.json")

在不进行调试的情况下,我的应用程序可以成功运行。请解释一下问题出在哪里...

英文:

I'm trying to debug my goland app and have some problems with launch.json file. My app should be run with argument: my_go_app -c path_to_config.

My launch.json looks like:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch my go app",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c /home/roman/projects/myapp/some.json"]
        }
    ]
}

But when I debug app I have received the following error:

flag provided but not defined: -c /home/roman/projects/myapp/some.json
Usage of /tmp/__debug_bin542579318:
-c string
Specify the configuration file. (default "config.json")

Without debugging my app runs with success. Please explain what is wrong...

答案1

得分: 2

我已经找到问题所在。JSON应该像这样:

{
    // 使用 IntelliSense 了解可能的属性。
    // 悬停以查看现有属性的描述。
    // 获取更多信息,请访问:https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "启动我的 Go 应用",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c", "/home/roman/projects/myapp/some.json"]
        }
    ]
}
英文:

I have found where is problem. The json should be like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch my go app",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c",  "/home/roman/projects/myapp/some.json"]
        }
    ]
}

huangapple
  • 本文由 发表于 2021年10月26日 19:30:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/69722294.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定