-
-
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
Stabilise AppSettings::Multicall
Tracking Issue
#2861
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Note: I had assumed #2817 was merged when preparing to write this. I've intentionally not posted it on #2817 after finding out because I don't think we should gate resolution of that PR on further design discussions For #2864, #2865, and #2866, I wonder if we should make some simplifying assumptions. Currently, #2817 bakes in one multi-call policy and these are about the impact of that or for supporting a variety of other multi-call policies. Instead on taking on the burden to support all multi-call policies, what if we generalize multi-call policy in clap and put the burden on the developer? Proposal:
Benefits
Downside
I'm assuming a trade off like this is worth it because the percentage of multicall users is probably fairly low and so the cost of taking on that extra boiler plate is low, in aggregate across users, compared to the cost for everyone else. |
I added a checklist item
I didn't create an issue because I think it might strictly be possible but its going to be non-obvious. More work might be needed around this. |
So… no matching against base program name, no checking whether the applet exists before I think the way that differs from AppSettings::NoBinaryName is that
So you mean something like this? #[derive(Parser)]
struct ConnectCommand(SocketAddr);
#[derive(Parser)]
enum DeceaseCommand {
GenerateKeys,
Connect(ConnectCommand),
Handshake,
Listen,
}
#[derive(Parser)]
enum Applet {
#[clap(name = concat!(env!("PROGRAM_PREFIX"), "decease"))]
Decease(DeceaseCommand),
#[clap(name = concat!(env!("PROGRAM_PREFIX"), "decease-generate-keys"))]
DeceaseGenerateKeys,
#[clap(name = concat!(env!("PROGRAM_PREFIX"), "decease-connect"))]
DeceaseConnect(ConnectCommand),
#[clap(name = concat!(env!("PROGRAM_PREFIX"), "decease-handshake"))]
DeceaseHandshake,
#[clap(name = concat!(env!("PROGRAM_PREFIX"), "decease-listen"))]
DeceaseListen,
} $ export PROGRAM_PREFIX=dcs-
$ cargo build
$ for name in decease decease-generate-keys decease-connect decease-handshake decease-listen; do ln target/debug/decease ~/bin/"$PROGRAM_PREFIX$name"; done I think this would work okay for derive-style, since the subcommand names get mapped to an enum variant internally, though I think it could be a lot of work for builder-style to keep adding the prefix. I think native support for prefixes would be nice to add later to reduce the duplication in the definition, but isn't needed. |
@fishface60 something I was considering is how should a user provide a sane fallback if the binary is not a recognized name? We have #2862 about the error message but that isn't always what a user will want. We could tell users to setup an "external subcommand" and then re-parse it with their default subcommand name. This might be rare enough that the performance hit is acceptable. This also gives users the opportunity to report it to the user as they wish (log a warning, custom error, etc). |
#3677 polished up a lot about multicall. My main concern at this point is the fallback on unrecognized binary. We are still just showing a regular "Unrecognized subcommand" error (#2862). Possible directions the user might want to go
I feel like a new error kind is probably the only reasonable way to go. |
Actually, can't |
I think we'll stablize as-is. If we get feedback that this needs a dedicated |
`multicall` allows you to have one binary expose itself as multiple programs, like busybox does. This also works well for user clap for parsing REPLs. Fixes clap-rs#2861
`multicall` allows you to have one binary expose itself as multiple programs, like busybox does. This also works well for user clap for parsing REPLs. Fixes clap-rs#2861
`multicall` allows you to have one binary expose itself as multiple programs, like busybox does. This also works well for user clap for parsing REPLs. Fixes clap-rs#2861
`multicall` allows you to have one binary expose itself as multiple programs, like busybox does. This also works well for user clap for parsing REPLs. Fixes clap-rs#2861
Original request: #1120
Original PR: #2817
Feature flag:
unstable-multicall
Known issues:
The text was updated successfully, but these errors were encountered: