Skip to content

Commit

Permalink
Add --no-inline-aliases option
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaddeo committed Sep 12, 2024
1 parent 179bc68 commit 7bd6243
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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::<String>(arg::SHELL).map(Into::into),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) use {
},
snafu::{ResultExt, Snafu},
std::{
borrow::Cow,
cmp,
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
env,
Expand Down
64 changes: 37 additions & 27 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
}

Expand Down

0 comments on commit 7bd6243

Please sign in to comment.