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

Support single-character flags #26

Open
2 tasks done
mmkal opened this issue Jun 17, 2024 · 3 comments · May be fixed by #27
Open
2 tasks done

Support single-character flags #26

mmkal opened this issue Jun 17, 2024 · 3 comments · May be fixed by #27
Labels
enhancement New feature or request pr welcome

Comments

@mmkal
Copy link

mmkal commented Jun 17, 2024

Feature request

It would be good to be able to define a flag that's only one character.

Motivations

I came across it while implementing trpc-cli, which uses cleye under the hood.

There are valid use cases for for single-character flags that aren't abbreviations, like plot --x 1 --y 2

Alternatives

Of course it will usually be possible to do awkward workarounds like plot --xx 1 --yy 2, and use x and y as aliases, and override documentation to suggest only using plot -x 1 -y 2, but this is cumbersome.

Additional context

I imagine the restriction is because it muddies the water a bit with aliases (would be confusing to have --x mean one thing, but -x be an alias for something else). If that's the reason for the restriction, maybe there could be a check added to make sure the alias exactly matches the "long" form.

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work financially will speed up resolution

  • I'm willing to offer financial support
@mmkal mmkal added the enhancement New feature or request label Jun 17, 2024
@privatenumber
Copy link
Owner

privatenumber commented Jun 18, 2024

Thanks for your sponsorship!

The x/y coordinates input are compelling use-cases for supporting this, and I'm happy to brainstorm how we can make this happen.

I think there could be a conflict with type-flag's alias grouping, which is a common practice in many UNIX commands. For example git commit -am 'message' groups flags a and m. I think this functionality might be mutually exclusive with single-character flag names.

EDIT: Or maybe not if we add support for alias-only flags. Thereby supporting your use-case with -x (not --x). Would this work?

@mmkal
Copy link
Author

mmkal commented Jun 18, 2024

I think that would work, yes. It'd probably be how most users would guess a cli should be used too. It kinda forces a particular usage but that's ok because it's a more convenient usage.

It'd be good enough for trpc-cli I think - a use case I wanted to cover was just throwing pretty much any trpc router at it and getting a functional CLI. That broke down for single-letter input props but a change like you suggest would cover them.

(V welcome re sponsorship. Thank you for your libraries - I am using more and more I find!)

@privatenumber
Copy link
Owner

I marked this as "pr welcome".

I'm not able to make time for this at the moment but feel free to tackle it if you'd like.

@mmkal mmkal linked a pull request Jun 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants