I am having difficulty in passing command-line arguments in VSCode (debug mode) with golang.
Below is the small code example and the launch.json:
package main
import (
"flag"
"fmt"
)
func main() {
flag1Ptr := flag.Bool("flag1", false, "flag1 is a flag")
flag.Parse()
fmt.Println(*flag1Ptr)
fmt.Println("Hello, world")
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": [
"-flag1"
]
}
]
}
The output is always "false" for *flag1Ptr but it should be "true".
Update: The issue disappeared after closing down VSCode and reopening it (I am on a Mac(osX))
