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

Add short forms for some flags #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

boomshroom
Copy link

The default flags package for go has fairly poor documentation regarding how to do short and long forms of flags. The simplest way to do this appears to be to define separate flags that write to the same pointer, and then override the help text so that they get shown together.

This PR currently defines:

  • -f for --follow
  • -l for --lang
  • -F for --quit-if-one-screen
  • -w for --wrap
  • -V for --version
  • -h for --help is automatically checked by the upstream package, but neither form was listed in the default help text
  • Suggestions for further short flags or changed flags would be welcome

The overridden help text I made prints each flag, including -h/--help, on a single line, with short flags, long flags, and descriptions each being column-aligned. It also uses double-dashes for long flags, and while the ability to use single-dashes is needed for short-flag support, the default help text only using single-dashes was very confusing, at least to me.

Due to how the default flags package works, while the custom help text only shows single-dashes for short flags and double-dashes for long flags, the other way around will still be parsed and accepted. This comes with the perhaps surprising quirk that multiple short flags need to be separated by spaces, rather than being accepted as compound flags that all share a single-dash.

Being new to this project, I am uncertain regarding style choices and am willing to modify the way things are written to better fit the established code (for example: changing the help text from a large constant string into a sequence of fmt.Println statements). I am also willing to change the format of the help text if desired.

Resolves #98

This include `-V` for `--version`, `-w` for `--wrap`,
`-f` for `--follow`, `-l` for `--lang`, and
`-F` for `--quit-if-one-screen`. Suggestions for changed
or additional short flags would be welcome.
This lets the help text better communicate the intended ways
to use short vs long options, lets related short and long
options appear together, and may arguably just be cleaner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ feature request ] provide short options to long options
1 participant