Short subcommands #1751
-
Use caseWhen subcommands are used a lot, you'd like them to be short ( Wanted solutionIn short, allow the following:
This would then show up like this (or similar, no strong preference):
I'm fine with them not being available in autocompletion or otherwise. ApplicationI would really like this for something I'm about to make, and I plan to use subcommands a bit. So this would increase the usability considerably. Bonus-feature: allow 'minimal matching' globally, to fuzzy match to the one fitting most - if there are multiple matching ones left, ask which one was meant (similar to the miss-spelling of arguments currently). Bonus-feature2: (Auto?-)generate unique shorter versions of all available (sub-)commands (/arguments?) Those would be pretty awesome. Edit: Changed example to |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 11 replies
-
We have |
Beta Was this translation helpful? Give feedback.
-
Ah, wow, I was unaware of that. That is really awesome! Well, this solves it only sort of. I would like to be able to exactly specify at least one shortened one, e.g. |
Beta Was this translation helpful? Give feedback.
-
Ah. Yes. Thank you. Maybe a general recommendation: Even though it is in the documentation, I was apparently unable to find it. Maybe make a full referenced feature-list somewhere or cross-reference these 'similar' features? |
Beta Was this translation helpful? Give feedback.
-
I have been thinking about appending the issue template with a small FAQ On Wed, Mar 18, 2020, 00:09 Felix notifications@github.com wrote:
|
Beta Was this translation helpful? Give feedback.
-
is there a way to derive this? my implementation looks like this use clap::{Parser, Subcommand};
use commands::{
download::DownloadCommands, email::EmailCommands, gitignore::GitIgnoreCommands,
readme::ReadmeCommands, sms::SmsCommands,
};
use crate::commands;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Utils {
#[command(subcommand)]
pub command: Commands,
}
impl Utils {
pub fn run() {
let utils = Utils::parse();
match utils.command {
Commands::GitIgnore(git_ignore) => git_ignore.parse(),
Commands::Readme(readme) => readme.parse(),
_ => panic!(),
}
}
}
#[derive(Subcommand)]
pub enum Commands {
/// download files, videos, etc
Download(DownloadCommands),
/// send email
Email(EmailCommands),
/// generate project readmes
Readme(ReadmeCommands),
///send SMS
Sms(SmsCommands),
/// handle git operations
// Git(GitCommands),
/// include .gitignore
GitIgnore(GitIgnoreCommands),
} |
Beta Was this translation helpful? Give feedback.
-
How do you print the alias when using --help? I am testing using clap 4.4.6, alias work but when using --help it only prints the Commands:
But how to print something like:
|
Beta Was this translation helpful? Give feedback.
alias
?