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

x/tools/cmd/stringer: document -linecomment in 'go doc stringer' #29867

Closed
tredoe opened this issue Jan 22, 2019 · 7 comments
Closed

x/tools/cmd/stringer: document -linecomment in 'go doc stringer' #29867

tredoe opened this issue Jan 22, 2019 · 7 comments
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tredoe
Copy link

tredoe commented Jan 22, 2019

This proposal is for that the 'stringer' tool gets flexibility at return strings, because the names that it returns are cased as they are in the values defined.

Problem

type systemKind int

const (
	Windows systemKind = iota
	MacOS
	Linux
	Android
	Ios
)
$ stringer -type systemKind ./test_data/

The names that it generates are WindowsMacOSLinuxAndroidIos.
But sometimes you want show the name of other way, e.g.
"macOS" for "MacOS" or "iOS" for "Ios"

So, the name given to define a constant has not to be the name wanted to be showed into a string.

Also, I would want to get other funcion name to get the string given into a tag string.

Proposal

Using a tag string like str to generate an alternative name, and with an optional tag name (e.g. long) to generate a funcion where return the string.

const (
	Windows systemKind = iota
	MacOS // `str:"macOS"`
	Linux     // `long:"the best system"`
	Android
	Ios // `str:"iOS"`
)

So the method (i systemKind) String() would get WindowsmacOSLinuxAndroidiOS.

And it would add a second method, e.g. (systemKind) LongString()
where it would return "the best system" for the value Linux.

@gopherbot gopherbot added this to the Proposal milestone Jan 22, 2019
@mvdan
Copy link
Member

mvdan commented Jan 22, 2019

Duplicate of #20483. See the solution there, which has been implemented for over a year.

@mvdan mvdan closed this as completed Jan 22, 2019
@tredoe
Copy link
Author

tredoe commented Jan 22, 2019

Sorry, but it doesn't solve the issue to generate a second method with other string.

@mvdan
Copy link
Member

mvdan commented Jan 22, 2019

Sure. You're mixing two proposals, though. Stringer generates exactly one method per type, and extra methods have been rejected in the past. For example, see #23535.

@mvdan mvdan reopened this Jan 22, 2019
@ianlancetaylor
Copy link
Contributor

The stringer tool is intentionally simple, and making it more complicated will, well, make it more complicated. You can certainly use it as the basis for a tool that does what you want.

@rsc
Copy link
Contributor

rsc commented Jan 23, 2019

@griesemer points out there is an undocumented stringer -linecomment mode that basically does what you are asking for. See https://golang.org/src/cmd/compile/internal/syntax/tokens.go for an example.

@rsc rsc changed the title proposal: different case with stringer tool x/tools/cmd/stringer: document -linecomment in 'go doc stringer' Jan 23, 2019
@rsc rsc modified the milestones: Proposal, Unreleased Jan 23, 2019
@rsc
Copy link
Contributor

rsc commented Jan 23, 2019

Marked declined but we should absolutely document this useful feature.

@bcmills bcmills added NeedsFix The path to resolution is known, but the work has not been done. help wanted labels May 28, 2019
@gopherbot
Copy link

Change https://golang.org/cl/191309 mentions this issue: x/tools/cmd/stringer: document -linecomment in the GoDoc

jocgir pushed a commit to jocgir/gotools that referenced this issue Apr 29, 2020
Fixes golang/go#29867
Change-Id: I0328a97c9e2ee4b42a0b0d2b9948bf69a6ee3322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191309
Reviewed-by: Rob Pike <r@golang.org>
@golang golang locked and limited conversation to collaborators Aug 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants