Skip to content
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/internal/fmtcmd: support format files in multiple directories #45627

Closed
ianwoolf opened this issue Apr 19, 2021 · 7 comments
Closed

cmd/go/internal/fmtcmd: support format files in multiple directories #45627

ianwoolf opened this issue Apr 19, 2021 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@ianwoolf
Copy link
Contributor

ianwoolf commented Apr 19, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.3 darwin/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ianwoolf/Library/Caches/go-build"
GOENV="/Users/ianwoolf/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ianwoolf/code/go/pkg/mod"
GONOPROXY="*.10101111.com"
GONOSUMDB="*.10101111.com"
GOOS="darwin"
GOPATH="/Users/ianwoolf/code/go"
GOPRIVATE="*.10101111.com"
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ianwoolf/code/go/src/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3f/x8jl0lgx629d_5bz0537gxnm0000gn/T/go-build3157445082=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

the function go/internal/load.PackagesAndErrors only support the files with all patterns referring to either:

- Files that are part of the same directory.
- Explicit package paths or patterns.

So go fmt do not support files in multiple directories, a command like go fmt a/a.go b/b.go will get an error msg named files must all be in one directory; have.....

But go fmt support mulitple pkg, e.g: go fmt a/ b/.

It seems that files in multiple directories should be supported.

What did you expect to see?

could go fmt files in muliple directories. such as: go fmt a/a.go b/b.go

What did you see instead?

get error msg like named files must all be in one directory; have....

@gopherbot
Copy link

Change https://golang.org/cl/311249 mentions this issue: cmd/go/internal/fmtcmd: support format files in multiple directories

1 similar comment
@gopherbot
Copy link

Change https://golang.org/cl/311249 mentions this issue: cmd/go/internal/fmtcmd: support format files in multiple directories

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 20, 2021
@toothrot toothrot added this to the Backlog milestone Apr 20, 2021
@toothrot
Copy link
Contributor

cc: @robpike @martisch

@ianwoolf
Copy link
Contributor Author

@bcmills
Copy link
Contributor

bcmills commented Apr 27, 2021

In general the arguments to go subcommands follow https://tip.golang.org/cmd/go/#hdr-Package_lists_and_patterns:

Many commands apply to a set of packages:

go action [packages]

Usually, [packages] is a list of import paths.

As a special case, if the package list is a list of .go files from a single directory, the command is applied to a single synthesized package made up of exactly those files, ignoring any build constraints in those files and ignoring any other files in the directory.

In theory go fmt could be made to accept wider patterns than the other subcommands, but at the moment I don't see a compelling reason to do so — it adds a fair amount of complexity to the go fmt implementation in order to support a use-case that seems can already be handled fairly straightforwardly using xargs or a similar command wrapper.

@bcmills bcmills modified the milestones: Backlog, Unplanned Apr 27, 2021
@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 27, 2021
@bcmills
Copy link
Contributor

bcmills commented Apr 27, 2021

@ianwoolf, is there a particular use-case that cannot be handled without this? Otherwise, I don't think it's worth the extra complexity of deviating from the patterns accepted by the other go subcommands.

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants