incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
607 stars 72 forks source link

attempt to handle --version even in untagged builds #161

Closed n-oden closed 5 days ago

n-oden commented 4 months ago

This addresses https://github.com/incu6us/goimports-reviser/issues/155

If we are installed via go-install rather than downloading a tagged binary from github, the Tag etc variables will all be empty, and therefore the --version flag is diked out. But there is a way around this!

If the version info is not filled in via build-time flags, use debug.BuildInfo to introspect as much information as we can out of the module metadata:

$ go install github.com/odenio/goimports-reviser/v3@v3.6.6-pre5
go: downloading github.com/odenio/goimports-reviser/v3 v3.6.6-pre5

$ ~/go/bin/goimports-reviser --version
version: 3.6.6-pre5
built with: go1.22.4
tag: v3.6.6-pre5
commit: n/a
source: github.com/odenio/goimports-reviser/v3

Additionally, add a --version-only flag that prints only the version string itself, handy for use in shell pipelines. Can be used on its own or in combination with the --version flag:

$ ~/go/bin/goimports-reviser --version-only
3.6.6-pre5
ccoVeille commented 4 months ago

I would love that!

There are so many tools with the frustrating "Dev" version

n-oden commented 4 months ago

Thanks for the approval! Can someone merge this? I cannot.

ccoVeille commented 4 months ago

I'm a random Gopher. You will have to wait for a maintainer review

n-oden commented 3 months ago

For the record if anyone would like to kick the tires on this, https://github.com/incu6us/goimports-reviser/pull/160 and https://github.com/incu6us/goimports-reviser/pull/159, I've made a build containing all three patches available as github.com/odenio/goimports-reviser/v3@v3.6.6-pre6.

I don't intend to maintain a long-lived fork here, but I understand that the maintainer may have bigger fish to fry at the moment, residing in Ukraine.

alexandear commented 5 days ago

@incu6us would you mind reviewing this?

n-oden commented 4 days ago

Thank you!

incu6us commented 3 days ago

Thank you!

Thank you for your contribution!