-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 multiple arguments writing to the same destination #3146
Comments
Is there a good workaround for this? I have a lot of options that are negatable (mostly using |
Maybe. In my case I only want these options for a few of the options, and in some cases I the man option starts with I'm also not really sure what the best way to do that when using the derive api would be. |
@tmccombs if your interest is in negation flags, be sure to watch the more specific #815. In it, I do bring up a more unusual solution using ArgAction so there is room for solutions outside of this issue. |
Some other use cases for this:
|
Right now wezterm already allows to pass a cmdline to execute (instead of the shell) by calling "wezterm start" with trailing arguments, e.g. wezterm start -- bash However, most other terminals implement this via a "-e" option. This seems to be adopted widely in the wild, such that some third-party frameworks just blindly expect the user's terminal to use the "-e" option for this. One such notable framework is kio from KDE Plasma, that calls the user's terminal in that way when launching a desktop file that uses Terminal=true. [1] To solve this problem, we add a compatibility layer by adding a dummy "-e" option. This will then consume the "-e" leaving the remaining arguments as trailing arguments, which will later be consumed by our existing implementation in the "prog" option. Given that clap does not really support multiple arguments writing to the same destination [2], this seems like the most sane implementation, even if it is a hack. It seems to work reliable, even for edge cases where we pass wezterm options as trailing arguments, e.g. the following will just work and do the expected outcome (and will **not** parse "--position" as a wezterm argument): wezterm start -e echo --position 10,10 Fixes wez#2622 [1] https://bugs.kde.org/show_bug.cgi?id=459616 [2] clap-rs/clap#3146
Right now wezterm already allows to pass a cmdline to execute (instead of the shell) by calling "wezterm start" with trailing arguments, e.g. wezterm start -- bash However, most other terminals implement this via a "-e" option. This seems to be adopted widely in the wild, such that some third-party frameworks just blindly expect the user's terminal to use the "-e" option for this. One such notable framework is kio from KDE Plasma, that calls the user's terminal in that way when launching a desktop file that uses Terminal=true. [1] To solve this problem, we add a compatibility layer by adding a dummy "-e" option. This will then consume the "-e" leaving the remaining arguments as trailing arguments, which will later be consumed by our existing implementation in the "prog" option. Given that clap does not really support multiple arguments writing to the same destination [2], this seems like the most sane implementation, even if it is a hack. It seems to work reliable, even for edge cases where we pass wezterm options as trailing arguments, e.g. the following will just work and do the expected outcome (and will **not** parse "--position" as a wezterm argument): wezterm start -e echo --position 10,10 Fixes wez#2622 [1] https://bugs.kde.org/show_bug.cgi?id=459616 [2] clap-rs/clap#3146
Right now wezterm already allows to pass a cmdline to execute (instead of the shell) by calling "wezterm start" with trailing arguments, e.g. wezterm start -- bash However, most other terminals implement this via a "-e" option. This seems to be adopted widely in the wild, such that some third-party frameworks just blindly expect the user's terminal to use the "-e" option for this. One such notable framework is kio from KDE Plasma, that calls the user's terminal in that way when launching a desktop file that uses Terminal=true. [1] To solve this problem, we add a compatibility layer by adding a dummy "-e" option. This will then consume the "-e" leaving the remaining arguments as trailing arguments, which will later be consumed by our existing implementation in the "prog" option. Given that clap does not really support multiple arguments writing to the same destination [2], this seems like the most sane implementation, even if it is a hack. It seems to work reliable, even for edge cases where we pass wezterm options as trailing arguments, e.g. the following will just work and do the expected outcome (and will **not** parse "--position" as a wezterm argument): wezterm start -e echo --position 10,10 Fixes #2622 [1] https://bugs.kde.org/show_bug.cgi?id=459616 [2] clap-rs/clap#3146
Please complete the following tasks
Clap Version
3.0.0-rc.0
Describe your use case
Related issues
Describe the solution you'd like
In Python's
argparse
, you can assign thedest
(for us,name
) for an argument in theNamespace
(for us,ArgMatches
). This gives a lot of power. One example is #1820 with migrating flags. The thing I used this most frequently for was negations (#815).The code would look something like
This makes it easy to define and handle and gives good semantics (last writer wins)
For now, I'm doing stuff like
https://github.com/epage/git-stack/blob/main/src/bin/git-stack/args.rs#L105
and haven't played with
overrides_with
to see what a last-writer-wins would look like with clap.Alternatives, if applicable
No response
Additional Context
See #1820 which has several concerns over doing this. I especially expect problems with
global(true)
See #3119 for more use cases
The text was updated successfully, but these errors were encountered: