cmd/go: provide some way to get the gofmt binary path

v8wbuo2f  于 3个月前  发布在  Go
关注(0)|答案(4)|浏览(67)

我们可以询问cmd/go编译器的路径:

$ go tool -n compile
/Users/josh/go/tip/pkg/tool/darwin_amd64/compile

似乎没有办法询问cmd/go二进制文件的位置。

$ go tool -n fmt
go tool: no such tool "fmt"
$ go fmt -n
can't load package: package .: found packages main (w.go) and p (x.go) in /Users/josh/go/tip/src

cc @rsc@bcmills

wpcxdonn

wpcxdonn1#

$(go env GOROOT)/bin/gofmt ?

hgqdbh6s

hgqdbh6s2#

在相关问题中,正如我所说,OS特定的发行版(如deb或rpm包)并不总是包含GOROOT/bin中的gofmt二进制文件。

iqxoj9l9

iqxoj9l93#

比较 go fix , go vetgo doc :

$ GO111MODULE=off go fix -n
flag provided but not defined: -n
usage: go fix [packages]
Run 'go help fix' for details.

$ GO111MODULE=off go vet -n
can't load package: package .: no Go files in /tmp/tmp.L5dpPjzEzQ

$ GO111MODULE=off go doc -n
flag provided but not defined: -n
Usage of [go] doc:
        go doc
        go doc <pkg>
        go doc <sym>[.<method>]
        go doc [<pkg>].<sym>[.<method>]
        go doc <pkg> <sym>[.<method>]
For more information run
        go help doc

Flags:
  -all
        show all documentation for package
  -c    symbol matching honors case (paths not affected)
  -cmd
        show symbols with package docs even if package is a command
  -src
        show source code for symbol
  -u    show unexported symbols as well as exported
exit status 2

可以认为它们都应该是一致的,因为它们调用了其他工具,并设置了由 cmd/go 设置的标志。

js81xvg6

js81xvg64#

@bcmills 也许我遗漏了什么,但我认为应该一致的是 go tool -n <toolname> 。修复、验证和文档目前至少通过了那个测试:

$ go tool -n fix
/Users/josh/go/tip/pkg/tool/darwin_amd64/fix
$ go tool -n vet
/Users/josh/go/tip/pkg/tool/darwin_amd64/vet
$ go tool -n doc
/Users/josh/go/tip/pkg/tool/darwin_amd64/doc

相关问题