Skip to content

x/tools/cmd/stringer to accept string input #60228

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

Closed
suntong opened this issue May 16, 2023 · 2 comments
Closed

x/tools/cmd/stringer to accept string input #60228

suntong opened this issue May 16, 2023 · 2 comments
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@suntong
Copy link

suntong commented May 16, 2023

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

$ go version
go version go1.19.3 linux/amd64

What did you want?

Given the name of a (signed or unsigned) integer type T that has constants
defined, stringer will create a new self-contained Go source file implementing

func (t T) String() string

That method will translate the value of a Pill constant to the string representation
of the respective constant name, so that the call fmt.Print(painkiller.Aspirin) will
print the string "Aspirin".

I need to pass the string representation from command line and get the corresponding integer value of type T.
EG, giving an input string "Aspirin", I need a method to get the corresponding value of Aspirin (1).

It is not possible at the moment right? Hope it'll be some day.
And meanwhile, while waiting, what shall I do? Can I still make use of the automatic created methods / code, or I should be looking for something entirely different?

Thanks

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 16, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 16, 2023
@suntong suntong closed this as completed May 16, 2023
@suntong suntong reopened this May 16, 2023
@suntong
Copy link
Author

suntong commented May 16, 2023

The challenge is when using the -linecomment=true. IE the value are different from the name.

See https://go.dev/play/p/t8n91_GF0Od

Given a string "Or", I need to get its value of "|". thx.

@randall77
Copy link
Contributor

Dup of #23535.

@golang golang locked and limited conversation to collaborators May 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants