New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josharian opened this Issue Aug 23, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@josharian
Contributor

josharian commented Aug 23, 2018

We can ask cmd/go for the path to cmd/compile:

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

There does not seem to be any way to ask cmd/go where the gofmt binary is.

$ 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

@rsc

This comment has been minimized.

Contributor

rsc commented Sep 26, 2018

$(go env GOROOT)/bin/gofmt?

@zolotov

This comment has been minimized.

Contributor

zolotov commented Sep 27, 2018

@rsc as I said in the related issue, OS-specific distributions (like deb or rpm packages) doesn't always contain gofmt binary in GOROOT/bin.

@bcmills bcmills added the GoCommand label Nov 15, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 15, 2018

Compare go fix, go vet, and go 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

Arguably those should all be consistent, in that they invoke other tools with flags set by cmd/go.

@bcmills bcmills modified the milestones: Go1.12, Go1.13 Nov 15, 2018

@josharian

This comment has been minimized.

Contributor

josharian commented Nov 15, 2018

@bcmills maybe I'm missing something, but I think the thing that should be consistent is go tool -n <toolname>. fix, vet, and doc currently at least pass that test:

$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment