Closed
Description
$ go version
go version devel +2b50ab2aee Tue Mar 2 06:38:07 2021 +0000 linux/amd64
When writing scripts, my workflow is usually:
- Do a
go list -json
query to find the fields/info I need - Narrow that down with
-f
, so I can then get the field I need directly - Write the script with the
-f
form
Sometimes, because I'm forgetful, I'll do step 2 as go list -json -f {{.Field}}
without removing -json
. That happened today again, and I was really confused for a solid five minutes:
$ go list -json unsafe
{
"Dir": "/home/mvdan/tip/src/unsafe",
"ImportPath": "unsafe",
"Name": "unsafe",
"Doc": "Package unsafe contains operations that step around the type safety of Go programs.",
"Root": "/home/mvdan/tip",
"Match": [
"unsafe"
],
"Goroot": true,
"Standard": true,
"GoFiles": [
"unsafe.go"
]
}
$ go list -json -f {{.Dir}} unsafe
{
"Dir": "/home/mvdan/tip/src/unsafe",
"ImportPath": "unsafe",
"Name": "unsafe",
"Doc": "Package unsafe contains operations that step around the type safety of Go programs.",
"Root": "/home/mvdan/tip",
"Match": [
"unsafe"
],
"Goroot": true,
"Standard": true,
"GoFiles": [
"unsafe.go"
]
}
$ go list -f {{.Dir}} unsafe
/home/mvdan/tip/src/unsafe
If both flags are present, I would expect one of the following:
- An error, telling the user that the two flags don't make sense together
- The
-f
flag would mean ignoring the-json
flag, as it's more specific
I think the first option makes more sense. Silently ignoring the -f
flag seems like the worst option to me.