-
-
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
Alias into subcomand #1603
Comments
I would like to work on this issue |
@Stupremee sure. you can go ahead and submit a PR. If you have any questions, you can post them here :) |
I have come up with 2 ways to implement this:
|
An idea I had was: App::new("rustup")
.mirror("install", "toolchain-install")
...
.subcommand(SubCommand::with_name("toolchain")
.subcommand(SubCommand::with_name("install")
.as_mirror("toolchain-install")
...
)
)
) Where the |
I like Again, I have yet to familiarize myself with clap internals (except for some) so I can't tell which way would be easier to implement. Let's postpone it until we dealt with clap_derive (I'll get to it in ~30 mins) |
I was thinking more of |
Are you imagining |
Yeah I guess you got it |
So, I was looking to implement this, and as of now, I can simply do delegation to sibling commands. You can't delegate up. Is that okay? App::new("rustup")
.subcommand(App::new("install")
.delegate(["toolchain", "install"]))
.subcommand(App::new("toolchain")
.subcommand(App::new("install"))) |
That would be sufficient for |
Actually, we can do something like this: App::new("rustup")
.delegate(["install"], ["toolchain", "install"])
.subcommand(App::new("install"))
.subcommand(App::new("toolchain")
.subcommand(App::new("install"))) Which would be the same thing, but it actually allows us to delegate up too. Would require more checks though. // These runs `rustup install` logic if you run `rustup toolchain install`
App::new("rustup")
.delegate(["toolchain", "install"], ["install"])
.subcommand(App::new("install"))
.subcommand(App::new("toolchain")
.subcommand(App::new("install"))) |
Looks good to me. I don't see much of a usecase of delegating upwords. |
From |
I would like propagating things only down (this delegation is a form of propagation too), like it has been for all this time; global args and global settings has been propagating down. It's being done in one, up-bottom propagation step. Making an exception for @kinnison You're able to hide subcommands from help messages via |
I'm aware of |
I have been looking at this the past few days and I have realized that doing this requires large changes in parsing logic. I would like to instead throw an alternative. let install = App::new("install"); // The install command
App::new("rustup")
.subcommand(App::new("toolchain")
.subcommand(install.clone()))
.subcommand(install.settings(AppSettings::Hidden)) Doesn't this basically solve your use case? Also, this is more correct since if we are just aliasing to a different path, then it might have issues with args on parent subcommands ( |
@pksunkara the issue is that, while the arguments are correctly parsed in this case, the actual code still has to handle the fact that there are two entry points to the functionality. The advantage of alias over just mounting the same In short, we want to let the user say |
Could you explain why you do not want this?
You are still writing just one |
The issue comes after doing The point of having the alias at the Or are you saying that if I use your code, then |
My bad, I was thinking of a different architecture for the CLI. I was thinking |
@CAD97 I have the PR ready, please give it a look. |
Cross posting from #2836 for greater visibility
|
As far as I can tell, it's currently possible to alias command arguments and subcommands. For things such as rust-lang/rustup#2148 (comment), it'd be really nice if it's somehow possible to alias both "across" and "into" subcommands, e.g. treat
rustup install
the same asrustup toolchain install
, i.e. including all arguments and such configured for the target subcommand.The text was updated successfully, but these errors were encountered: