Pass arguments to Golang program when debugging with VSCode
I’m doing some work on a golang project, the code takes a relative file path in as an argument.
Now I have Delve, VSCode and VSCode-Go installed which means I can have a nice interactive debugging session. The only snag I hit was that it wasn’t clear how to pass in my arguments when the debugger started my go code.
The trick is the use a double dash to indicate which arguments should go to the code, other args, before this, will go to the delve debugger. Also don’t forget to use “cwd” to set the working dir used when debugging.
Here is an example with comments
https://gist.github.com/lawrencegripper/43f4bd28061181a593b0a08f348f2cef
And we’re away…
N.B The behavior is a bit odd, as the code here suggests that the “–” should be appended for you. https://github.com/Microsoft/vscode-go/blob/master/src/debugAdapter/goDebug.ts#L306. However, this did not work for me, may be fixed in the future so double check!