rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.1k stars 877 forks source link

Consider Inferred Subcommands #980

Open kbknapp opened 7 years ago

kbknapp commented 7 years ago

As of clap v2.21 there is a new setting that allows subcommands to be inferred so long as they're not ambiguous. Since rustup makes heavy use of long strings of subcommands this could greatly increase ergonomics.

For instance the following are equivilant:

$ rustup toolchain update stable
$ rustup to up stable

This also completely sidesteps the, "was it toolchain or toolchains?"

The only change that would be needed in the code is adding a line right after this one with the following:

.global_setting(AppSettings::InferSubcommands)

Thoughts?

brson commented 7 years ago

Thank you for the suggestions @kbknapp. I will think about it, but don't have an opinion now.

Diggsey commented 7 years ago

The problem with this is if people start relying on it in their scripts, or posting the shortened version in answers or blog posts online, then adding new commands becomes a breaking change.

What about interactively suggesting corrections to the correct subcommand instead? eg.

> rustup to up stable
Did you mean `rustup toolchain update stable?` [Y/n]

There would be no non-interactive option, and it only costs an extra return (since Y is the default). It could use fuzzy matching as well.

kbknapp commented 7 years ago

First, let me preface this with I don't have personal feelings for this suggestion either way. With CLIs that rely on long strings of subcommands it can help, but it's totally fine if y'all decide against it :-) I don't want my being the clap maintainer to come off as a bias for this feature, as it's simply a suggestion to consider.

As for the people relying on shortened versions in scripts and blogs; that's bad practice in general and I'd be inclined to say breakage stemming from that shouldn't be a huge concern. Not that it shouldn't be a concern, but just not a primary worry.

An interactive inference could work too, but I think that's much harder to implement with chained subcommands unless it's part of clap proper. Personally though, I try to stay away from any interaction during clap parsing and would rather have such features built on top (which is back to being hard :-P). However, it would be technically possible.

Another option is to use hidden aliases for common shortenings similar to how habitat and diesel do. And I would suggest at a minimum at least adding both the singular and plural forms of the appropriate subcommands.

On Mar 16, 2017 5:45 PM, "Diggory Blake" notifications@github.com wrote:

The problem with this is if people start relying on it in their scripts, or posting the shortened version in answers or blog posts online,, then adding new commands becomes a breaking change.

What about interactively suggesting corrections to the correct subcommand instead? eg.

rustup to up stable Did you mean rustup toolchain update stable? [Y/n]

There would be no non-interactive option, and it only costs an extra return (since Y is the default). It could use fuzzy matching as well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rust-lang-nursery/rustup.rs/issues/980#issuecomment-287214609, or mute the thread https://github.com/notifications/unsubscribe-auth/AGnttjsL1Shn2UFTNUr-4mSitjQPQhSUks5rmbuagaJpZM4MauJq .