dlipovetsky / goprintconst

CLI that prints const declarations in a Go file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goprintconst

If you use Go constants as the source of truth in your build, you might end up reading their values like this:

> grep -e "MySpecial.*=.*" "foo/bar.go"
    MySpecial    = "value"

This operation can be error-prone: The regular expression might be incorrect, commands like grep or cut might be unavailable. By walking the Go abstract syntax tree (AST) to find constants, goprintconst makes the operation reliable.

Use

> goprintconst --file foo/bar.go --name MySpecial
value

By default, string and character values are unquoted. To preserve quotes, use the -raw=false flag:

> goprintconst --file foo/bar.go --name MySpecial -raw=false
"value"

Install

go install github.com/dlipovetsky/goprintconst

About

CLI that prints const declarations in a Go file.

License:MIT License


Languages

Language:Go 100.0%