Skip to main content

Go-Flags VSCode snippet

Snippet for generating go-flags parameters in VS Code.

  1. Type CMD+SHIFT+P, write Snippets, and select Configure User snippets
  2. Type go and select go.json (Go)
  3. Add snippet
"Go-Flag": {
    "prefix": "gflag",
    "description": "Generate stub for go-flags package",
    "body": "$1 ${2:string} `long:\"${1/([a-z]+)(?=[A-Z])|([A-Z])(?=[A-Z])|([A-Z][a-z]+)(?=$)|([A-Z][a-z]+)|([a-z]+)(?=$)/${1:/downcase}${1:+-}${2:/downcase}${2:+-}${3:/downcase}${4:/downcase}${4:+-}${5:/downcase}/g}\" env:\"${1/([a-z]+)(?=[A-Z])|([A-Z])(?=[A-Z])|([A-Z][a-z]+)(?=$)|([A-Z][a-z]+)|([a-z]+)(?=$)/${1:/upcase}${1:+_}$2${2:+_}${3:/upcase}${4:/upcase}${4:+_}${5:/upcase}/g}\" description:\"$3\"`"
}

In the code type gflag and hit tab

References: