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

proposal: flag: Introduce functions for defining rune flag #41757

Closed
ghost opened this issue Oct 2, 2020 · 3 comments
Closed

proposal: flag: Introduce functions for defining rune flag #41757

ghost opened this issue Oct 2, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 2, 2020

Currently the flag package has functions for parsing string.

In order use a rune flag one has to

  1. define it as string flag
  2. check rune count using utf8.RuneCountInString to know if is has one or more rune.
  3. if rune count is more than one, produce an error or call flag.Usage and exit. ( But the usage information
    that flag.Usage gives will contain -flag string for that flag. so it requires to add `rune` to that flag's usage
    information to get flag.Usage show -flag rune for that flag's usage information. )
  4. type cast it to []rune
  5. get the first rune by using index 0
@gopherbot gopherbot added this to the Proposal milestone Oct 2, 2020
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Oct 2, 2020
@ianlancetaylor
Copy link
Contributor

The need for a flag that accepts a single rune seems 1) rare; 2) easy to implement by implementing the flag.Value interface. What is the argument for putting this in the standard library? See https://golang.org/doc/faq#x_in_std.

@rsc rsc moved this from Incoming to Active in Proposals (old) Oct 7, 2020
@rsc
Copy link
Contributor

rsc commented Oct 14, 2020

I'm at a loss to remember any program I've ever used that took a flag argument that was itself (the argument) required to be a single letter.

Note that you can implement this yourself using the new flag.Func (will be in Go 1.16) or using flag.Value.

@ghost ghost closed this as completed Oct 19, 2020
@rsc rsc moved this from Active to Declined in Proposals (old) Oct 21, 2020
@rsc
Copy link
Contributor

rsc commented Oct 21, 2020

(Retracted by author.)

@golang golang locked and limited conversation to collaborators Oct 21, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

3 participants