diff --git a/src/config.rs b/src/config.rs index 356c663f05..01669fe52c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ pub(crate) struct Config { pub(crate) list_submodules: bool, pub(crate) load_dotenv: bool, pub(crate) no_aliases: bool, + pub(crate) no_inline_aliases: bool, pub(crate) no_dependencies: bool, pub(crate) search_config: SearchConfig, pub(crate) shell: Option, @@ -97,6 +98,7 @@ mod arg { pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX"; pub(crate) const LIST_SUBMODULES: &str = "LIST-SUBMODULES"; pub(crate) const NO_ALIASES: &str = "NO-ALIASES"; + pub(crate) const NO_INLINE_ALIASES: &str = "NO-INLINE-ALIASES"; pub(crate) const NO_DEPS: &str = "NO-DEPS"; pub(crate) const NO_DOTENV: &str = "NO-DOTENV"; pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT"; @@ -274,6 +276,13 @@ impl Config { .action(ArgAction::SetTrue) .help("Don't show aliases in list"), ) + .arg( + Arg::new(arg::NO_INLINE_ALIASES) + .long("no-inline-aliases") + .env("JUST_NO_INLINE_ALIASES") + .action(ArgAction::SetTrue) + .help("Don't show aliases inline with recipe docs in list"), + ) .arg( Arg::new(arg::NO_DEPS) .long("no-deps") @@ -720,6 +729,7 @@ impl Config { list_submodules: matches.get_flag(arg::LIST_SUBMODULES), load_dotenv: !matches.get_flag(arg::NO_DOTENV), no_aliases: matches.get_flag(arg::NO_ALIASES), + no_inline_aliases: matches.get_flag(arg::NO_INLINE_ALIASES), no_dependencies: matches.get_flag(arg::NO_DEPS), search_config, shell: matches.get_one::(arg::SHELL).map(Into::into), diff --git a/src/lib.rs b/src/lib.rs index fe90bdc468..75e3332be4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub(crate) use { }, snafu::{ResultExt, Snafu}, std::{ + borrow::Cow, cmp, collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, diff --git a/src/subcommand.rs b/src/subcommand.rs index ec99b48bae..eacc3c4b30 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -563,37 +563,47 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { - let doc = recipe.doc(); - - if let Some(doc) = &doc { - if doc.lines().count() > 1 { - for line in doc.lines() { - println!( - "{list_prefix}{} {}", - config.color.stdout().doc().paint("#"), - config.color.stdout().doc().paint(line), - ); + for (i, name) in iter::once(&recipe.name()) + .chain(aliases.get(recipe.name()).unwrap_or(&Vec::new())) + .enumerate() + { + let doc = if i == 0 { + recipe.doc().map(Cow::Borrowed) + } else { + Some(Cow::Owned(format!("alias for `{}`", recipe.name))) + }; + + if let Some(doc) = &doc { + if doc.lines().count() > 1 { + for line in doc.lines() { + println!( + "{list_prefix}{} {}", + config.color.stdout().doc().paint("#"), + config.color.stdout().doc().paint(line), + ); + } } } - } - print!( - "{list_prefix}{}", - RecipeSignature { - name: recipe.name(), - recipe + if i == 0 || config.no_inline_aliases { + print!( + "{list_prefix}{}", + RecipeSignature { name, recipe }.color_display(config.color.stdout()) + ); + + format_doc( + config, + name, + doc.as_deref(), + aliases + .get(recipe.name()) + .filter(|_| !config.no_inline_aliases) + .cloned(), + max_signature_width, + &signature_widths, + ); } - .color_display(config.color.stdout()) - ); - - format_doc( - config, - recipe.name(), - doc, - aliases.get(recipe.name()).cloned(), - max_signature_width, - &signature_widths, - ); + } } }