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: go tool doesn't pass command name as os.Args[0] when flags are present #70509

Open
seankhliao opened this issue Nov 21, 2024 · 4 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@seankhliao
Copy link
Member

Go version

go version devel go1.24-efe0a86551 2024-11-21 20:50:15 +0000 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-trimpath "-ldflags=-s -w" -vet=all'
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3521496734=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/user/tmp/testrepo0896/go.mod'
GOMODCACHE='/home/user/.data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/.data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='path'
GOTOOLDIR='/home/user/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-efe0a86551 2024-11-21 20:50:15 +0000'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

With a basic tool like: https://go.dev/play/p/0MpgRS3gwFS
Invoking it results in:

$ go tool mytool
[/home/user/.cache/go-build/05/05c95035c59ab02d5d47f8b72f30bf94aafdbe7a97a027a1a3ac48961b3a0fda-d/mytool]

$ go tool mytool -hello world
[-hello world]

What did you see happen?

The tool doesn't receive its own name in os.Args[0], messing up argument / flag parsing.

What did you expect to see?

the usual os.Args

@seankhliao
Copy link
Member Author

@seankhliao seankhliao added the GoCommand cmd/go label Nov 21, 2024
@seankhliao seankhliao added this to the Go1.24 milestone Nov 21, 2024
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 22, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/631075 mentions this issue: go/cmd: pass os.Args[0] to mod tools

@ConradIrwin
Copy link
Contributor

Thanks for testing this out @seankhliao! - sent a fix, and please let me know if you run into anything else with this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants