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

Allow longer shorts #5377

Open
2 tasks done
jhesqqq opened this issue Feb 26, 2024 · 2 comments
Open
2 tasks done

Allow longer shorts #5377

jhesqqq opened this issue Feb 26, 2024 · 2 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@jhesqqq
Copy link

jhesqqq commented Feb 26, 2024

Please complete the following tasks

Clap Version

4.5.1

Describe your use case

Let short flag allow more characters than one to facilitate user input.

I know that short flags implement their combined behavior by default in clap, which prevents short flags from using more than two characters.
For example, ls -l-a = ls -la, which I think is a great feature.

However, implementing only this functionality ignores the case where the user does not want to enter the long flag if there are too many parameters.
For example, the user wants to type xxx-oJ instead of xxx --oJ

Describe the solution you'd like

I have a solution, which is that clap can open a method to control whether I want this default composition behavior or not.

When I turn off the composition behavior, the short flag length is at least 1 or greater.
For example, -oJ, the output is json, there is no combined behavior here, just a single instance.

When I enable the composition behavior (which is the default), the short flag is limited to a length of 1.
Which is now the composition behavior.

Alternatives, if applicable

No response

Additional Context

No response

@jhesqqq jhesqqq added the C-enhancement Category: Raise on the bar on expectations label Feb 26, 2024
@epage epage changed the title Allow longer short with the addition of closed composite behavior methods Allow longer shorts Feb 26, 2024
@epage epage added A-parsing Area: Parser's logic and needs it changed somehow. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing labels Feb 26, 2024
@epage
Copy link
Member

epage commented Feb 26, 2024

Renamed the title to focus on the problem, rather than solution.

I know this has been discussed before but not finding the Issues or Discussions for it. #1210 is either similar or the same thing, depending on your perspective.

There are several problems to solve

  • API: With clap v3, we intentionally switched short from accepting &str to char to better represent this limitation in type system
  • Behavior: we have to deal with people who want true shorts with combining of multiple flags + a value with people who want multi-character shorts. There might even people who want both.
    • If its both, that adds its own complexities.
    • If its either, then we have to balance the scope of how much this is needed vs the compile time and binary size of making this large of a behavior swap conditional
  • Implementation: this is a dramatic difference at the core of clap/s lexing and parsing

If this is more like #1210, then #2468 is likely the way forward.

@jhesqqq
Copy link
Author

jhesqqq commented Feb 27, 2024

I noticed that in v2, clap short allowed multiple characters, but only the first one was retrieved.
For example, short("abc") appears as -a on the command line.

API: With clap v3, we intentionally switched short from accepting &str to char to better represent this limitation in type system

I think developing a way to regulate whether or not composition behavior is used is a very important feature for developers and users.
The right sacrifice can sometimes be a big help.

Behavior: we have to deal with people who want true shorts with combining of multiple flags + a value with people who want multi-character shorts. There might even people who want both.

  • If its both, that adds its own complexities.
  • If its either, then we have to balance the scope of how much this is needed vs the compile time and binary size of making this large of a behavior swap conditional

I am aware of these issues and hope such issues can be resolved.

If this is more like #1210, then #2468 is likely the way forward.

Finally, I wish clap better and better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

2 participants