From 511c8fe2007a9b28acacc4c5d1ae71356569a832 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Tue, 3 Sep 2024 12:02:00 -0400 Subject: [PATCH 01/28] Condense aliases into the recipe doc --- src/lib.rs | 1 - src/subcommand.rs | 115 +++++++++++++++++++++++++--------------------- tests/misc.rs | 32 ++++++++----- 3 files changed, 84 insertions(+), 64 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7ce669ea1a..8355d63eb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,6 @@ 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 8d34578845..3f017a64b8 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -436,36 +436,50 @@ impl Subcommand { config: &Config, name: &str, doc: Option<&str>, + aliases: Option>, max_signature_width: usize, signature_widths: &BTreeMap<&str, usize>, ) { - if let Some(doc) = doc { - if !doc.is_empty() && doc.lines().count() <= 1 { - let color = config.color.stdout(); - print!( - "{:padding$}{} ", - "", - color.doc().paint("#"), - padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, - ); + let doc = doc.unwrap_or(""); + let aliases = aliases.unwrap_or(Vec::new()); + let print_doc = !doc.is_empty() && doc.lines().count() <= 1; + let color = config.color.stdout(); + + if print_doc || !aliases.is_empty() { + print!( + "{:padding$}{}", + "", + config.color.stdout().doc().paint("#"), + padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, + ); + } - let mut end = 0; - for backtick in backtick_re().find_iter(doc) { - let prefix = &doc[end..backtick.start()]; - if !prefix.is_empty() { - print!("{}", color.doc().paint(prefix)); - } - print!("{}", color.doc_backtick().paint(backtick.as_str())); - end = backtick.end(); + if print_doc { + print!(" "); + let mut end = 0; + for backtick in backtick_re().find_iter(doc) { + let prefix = &doc[end..backtick.start()]; + if !prefix.is_empty() { + print!("{}", color.doc().paint(prefix)); } + print!("{}", color.doc_backtick().paint(backtick.as_str())); + end = backtick.end(); + } - let suffix = &doc[end..]; - if !suffix.is_empty() { - print!("{}", color.doc().paint(suffix)); - } + let suffix = &doc[end..]; + if !suffix.is_empty() { + print!("{}", color.doc().paint(suffix)); } } + if !aliases.is_empty() { + print!( + " {}", + color + .doc() + .paint(&format!("[aliases: {}]", aliases.join(", "))) + ); + } println!(); } @@ -589,41 +603,37 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { - 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), - ); - } + 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), + ); } } + } - print!( - "{list_prefix}{}", - RecipeSignature { name, recipe }.color_display(config.color.stdout()) - ); + print!( + "{list_prefix}{}", + RecipeSignature { + name: recipe.name(), + recipe + } + .color_display(config.color.stdout()) + ); - format_doc( - config, - name, - doc.as_deref(), - max_signature_width, - &signature_widths, - ); - } + format_doc( + config, + recipe.name(), + doc.as_deref(), + aliases.get(recipe.name()).cloned(), + max_signature_width, + &signature_widths, + ); } } @@ -642,6 +652,7 @@ impl Subcommand { config, submodule.name(), submodule.doc.as_deref(), + None, max_signature_width, &signature_widths, ); diff --git a/tests/misc.rs b/tests/misc.rs index ab16d5e208..3e5af2f9fd 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -11,8 +11,23 @@ test! { args: ("--list"), stdout: " Available recipes: - foo - f # alias for `foo` + foo # [aliases: f] + ", +} + +test! { + name: alias_listing_with_doc, + justfile: " + # foo command + foo: + echo foo + + alias f := foo + ", + args: ("--list"), + stdout: " + Available recipes: + foo # foo command [aliases: f] ", } @@ -22,9 +37,7 @@ test! { args: ("--list"), stdout: " Available recipes: - foo - f # alias for `foo` - fo # alias for `foo` + foo # [aliases: f, fo] ", } @@ -34,8 +47,7 @@ test! { args: ("--list"), stdout: " Available recipes: - foo PARAM='foo' - f PARAM='foo' # alias for `foo` + foo PARAM='foo' # [aliases: f] ", } @@ -927,8 +939,7 @@ a: stdout: r" Available recipes: a - b - c # alias for `b` + b # [aliases: c] ", } @@ -942,8 +953,7 @@ a: args: ("--list", "--unsorted"), stdout: r" Available recipes: - b - c # alias for `b` + b # [aliases: c] a ", } From 70da034cf77cdb37f4fad23ce102504eef9841f2 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Tue, 3 Sep 2024 18:35:51 -0400 Subject: [PATCH 02/28] Fix clippy errors --- src/subcommand.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 3f017a64b8..86b475517d 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -441,7 +441,7 @@ impl Subcommand { signature_widths: &BTreeMap<&str, usize>, ) { let doc = doc.unwrap_or(""); - let aliases = aliases.unwrap_or(Vec::new()); + let aliases = aliases.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; let color = config.color.stdout(); @@ -629,7 +629,7 @@ impl Subcommand { format_doc( config, recipe.name(), - doc.as_deref(), + doc, aliases.get(recipe.name()).cloned(), max_signature_width, &signature_widths, From d3160925a3fb3936149378f315f27581f714f4f5 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Sat, 7 Sep 2024 12:34:57 -0400 Subject: [PATCH 03/28] Paint aliases in --list purple --- src/color.rs | 4 ++++ src/subcommand.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/color.rs b/src/color.rs index 7742597be4..b6fdcfc435 100644 --- a/src/color.rs +++ b/src/color.rs @@ -69,6 +69,10 @@ impl Color { self.restyle(Style::new().fg(Cyan)) } + pub(crate) fn alias(self) -> Self { + self.restyle(Style::new().fg(Purple)) + } + pub(crate) fn error(self) -> Self { self.restyle(Style::new().fg(Red).bold()) } diff --git a/src/subcommand.rs b/src/subcommand.rs index 86b475517d..acc57a4706 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -476,7 +476,7 @@ impl Subcommand { print!( " {}", color - .doc() + .alias() .paint(&format!("[aliases: {}]", aliases.join(", "))) ); } From 381a13c54adb829468535e6c6c57190512fc10f1 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Thu, 12 Sep 2024 11:23:02 -0400 Subject: [PATCH 04/28] Use unwrap_or_default --- src/subcommand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index acc57a4706..2df4da80f3 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -440,7 +440,7 @@ impl Subcommand { max_signature_width: usize, signature_widths: &BTreeMap<&str, usize>, ) { - let doc = doc.unwrap_or(""); + let doc = doc.unwrap_or_default(); let aliases = aliases.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; let color = config.color.stdout(); From 63671cff3744b93b5e5b64e3c52f0224d50f4045 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Thu, 12 Sep 2024 11:24:21 -0400 Subject: [PATCH 05/28] Add --no-inline-aliases option --- src/config.rs | 10 ++++++++ src/lib.rs | 1 + src/subcommand.rs | 64 +++++++++++++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/config.rs b/src/config.rs index df7e91ef56..ce5ca1824c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -28,6 +28,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) one: bool, pub(crate) search_config: SearchConfig, @@ -105,6 +106,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"; @@ -286,6 +288,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") @@ -763,6 +772,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), one: matches.get_flag(arg::ONE), search_config, diff --git a/src/lib.rs b/src/lib.rs index 8355d63eb4..7ce669ea1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,6 +111,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 2df4da80f3..b9af59ef4d 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -603,37 +603,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, - ); + } } } From fa06fff116c0572286d6f81cb6bd576534a646f8 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 13:31:13 -0400 Subject: [PATCH 06/28] Use a Vec for aliases in format_doc instead of Option --- src/subcommand.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index b9af59ef4d..fdc7114818 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -436,16 +436,15 @@ impl Subcommand { config: &Config, name: &str, doc: Option<&str>, - aliases: Option>, + aliases: &Vec<&str>, max_signature_width: usize, signature_widths: &BTreeMap<&str, usize>, ) { let doc = doc.unwrap_or_default(); - let aliases = aliases.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; let color = config.color.stdout(); - if print_doc || !aliases.is_empty() { + if print_doc || (!config.no_inline_aliases && !aliases.is_empty()) { print!( "{:padding$}{}", "", @@ -472,7 +471,7 @@ impl Subcommand { } } - if !aliases.is_empty() { + if !aliases.is_empty() && !config.no_inline_aliases { print!( " {}", color @@ -635,10 +634,7 @@ impl Subcommand { config, name, doc.as_deref(), - aliases - .get(recipe.name()) - .filter(|_| !config.no_inline_aliases) - .cloned(), + aliases.get(recipe.name()).unwrap_or(&Vec::new()), max_signature_width, &signature_widths, ); @@ -662,7 +658,7 @@ impl Subcommand { config, submodule.name(), submodule.doc.as_deref(), - None, + &Vec::new(), max_signature_width, &signature_widths, ); From 136fdb8e776cd3c8171ad31ced59e086eac77bc0 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 13:36:27 -0400 Subject: [PATCH 07/28] Fix clippy lint --- src/subcommand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index fdc7114818..77db4f1e3b 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -436,7 +436,7 @@ impl Subcommand { config: &Config, name: &str, doc: Option<&str>, - aliases: &Vec<&str>, + aliases: &[&str], max_signature_width: usize, signature_widths: &BTreeMap<&str, usize>, ) { From 3c8e1301ce3d13a2fc4a37e08433a2a880b86585 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 14:13:43 -0400 Subject: [PATCH 08/28] Alter the iterator instead of multiple conditionals --- src/subcommand.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 77db4f1e3b..ffdfd5db4e 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -602,8 +602,14 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { + let recipe_alias_entries = if config.no_inline_aliases { + aliases.get(recipe.name()) + } else { + None + }; + for (i, name) in iter::once(&recipe.name()) - .chain(aliases.get(recipe.name()).unwrap_or(&Vec::new())) + .chain(recipe_alias_entries.unwrap_or(&Vec::new())) .enumerate() { let doc = if i == 0 { @@ -624,21 +630,19 @@ impl Subcommand { } } - 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()).unwrap_or(&Vec::new()), - max_signature_width, - &signature_widths, - ); - } + print!( + "{list_prefix}{}", + RecipeSignature { name, recipe }.color_display(config.color.stdout()) + ); + + format_doc( + config, + name, + doc.as_deref(), + aliases.get(recipe.name()).unwrap_or(&Vec::new()), + max_signature_width, + &signature_widths, + ); } } } From a4c1b68b89ec3871ed0c99f8224081096becbc55 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 14:18:10 -0400 Subject: [PATCH 09/28] Convert test format --- tests/misc.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/misc.rs b/tests/misc.rs index 3e5af2f9fd..3187724e88 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -15,20 +15,27 @@ test! { ", } -test! { - name: alias_listing_with_doc, - justfile: " - # foo command - foo: - echo foo - - alias f := foo - ", - args: ("--list"), - stdout: " - Available recipes: - foo # foo command [aliases: f] - ", +#[test] +fn alias_listing_with_doc() { + Test::new() + .justfile( + " + # foo command + foo: + echo foo + + alias f := foo + ", + ) + .arg("--list") + .stdout( + " + Available recipes: + foo # foo command [aliases: f] + ", + ) + .status(EXIT_SUCCESS) + .run(); } test! { From 031d54610575dc29d2f46551cd3d5e95ea1ddc23 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 14:20:19 -0400 Subject: [PATCH 10/28] Add test for --no-inline-aliases --- tests/lib.rs | 1 + tests/no_inline_aliases.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/no_inline_aliases.rs diff --git a/tests/lib.rs b/tests/lib.rs index 3ee9c3801f..e719c31af1 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -89,6 +89,7 @@ mod no_aliases; mod no_cd; mod no_dependencies; mod no_exit_message; +mod no_inline_aliases; mod os_attributes; mod parameters; mod parser; diff --git a/tests/no_inline_aliases.rs b/tests/no_inline_aliases.rs new file mode 100644 index 0000000000..4194933777 --- /dev/null +++ b/tests/no_inline_aliases.rs @@ -0,0 +1,20 @@ +use super::*; + +#[test] +fn no_inline_aliases_flag() { + Test::new() + .justfile( + " + alias t := test1 + + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--no-inline-aliases", "--list"]) + .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") + .run(); +} From 663289f2637972351b93cc03c06c057944704db3 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 15:58:19 -0400 Subject: [PATCH 11/28] Move NO_INLINE_ALIASES to be in alpha order, and make it conflict with --no-aliases --- src/config.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index ce5ca1824c..c878e7c678 100644 --- a/src/config.rs +++ b/src/config.rs @@ -106,10 +106,10 @@ 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"; + pub(crate) const NO_INLINE_ALIASES: &str = "NO-INLINE-ALIASES"; pub(crate) const ONE: &str = "ONE"; pub(crate) const QUIET: &str = "QUIET"; pub(crate) const SET: &str = "SET"; @@ -293,7 +293,8 @@ impl Config { .long("no-inline-aliases") .env("JUST_NO_INLINE_ALIASES") .action(ArgAction::SetTrue) - .help("Don't show aliases inline with recipe docs in list"), + .help("Don't show aliases inline with recipe docs in list") + .conflicts_with(arg::NO_ALIASES), ) .arg( Arg::new(arg::NO_DEPS) From 5d97d8691e9f0a13413cc655cc172c945a8c1776 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 16:07:37 -0400 Subject: [PATCH 12/28] Add --inline-aliases-left flag to display aliases to the left of the doc --- src/config.rs | 12 ++++++++++++ src/subcommand.rs | 38 +++++++++++++++++++++++++++++--------- tests/list.rs | 19 +++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index c878e7c678..d242c0613e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ pub(crate) struct Config { pub(crate) dump_format: DumpFormat, pub(crate) explain: bool, pub(crate) highlight: bool, + pub(crate) inline_aliases_left: bool, pub(crate) invocation_directory: PathBuf, pub(crate) list_heading: String, pub(crate) list_prefix: String, @@ -101,6 +102,7 @@ mod arg { pub(crate) const EXPLAIN: &str = "EXPLAIN"; pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL-JUSTFILE"; pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT"; + pub(crate) const INLINE_ALIASES_LEFT: &str = "INLINE-ALIASES-LEFT"; pub(crate) const JUSTFILE: &str = "JUSTFILE"; pub(crate) const LIST_HEADING: &str = "LIST-HEADING"; pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX"; @@ -246,6 +248,15 @@ impl Config { .help("Highlight echoed recipe lines in bold") .overrides_with(arg::NO_HIGHLIGHT), ) + .arg( + Arg::new(arg::INLINE_ALIASES_LEFT) + .long("inline-aliases-left") + .env("JUST_INLINE_ALIASES_LEFT") + .action(ArgAction::SetTrue) + .help("Display inlined recipe aliases to the left of their doc in listing") + .conflicts_with(arg::NO_ALIASES) + .conflicts_with(arg::NO_INLINE_ALIASES), + ) .arg( Arg::new(arg::JUSTFILE) .short('f') @@ -767,6 +778,7 @@ impl Config { .clone(), explain, highlight: !matches.get_flag(arg::NO_HIGHLIGHT), + inline_aliases_left: matches.get_flag(arg::INLINE_ALIASES_LEFT), invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?, list_heading: matches.get_one::(arg::LIST_HEADING).unwrap().into(), list_prefix: matches.get_one::(arg::LIST_PREFIX).unwrap().into(), diff --git a/src/subcommand.rs b/src/subcommand.rs index ffdfd5db4e..c8a0148ee9 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -442,9 +442,10 @@ impl Subcommand { ) { let doc = doc.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; + let print_aliases = !config.no_inline_aliases && !aliases.is_empty(); let color = config.color.stdout(); - if print_doc || (!config.no_inline_aliases && !aliases.is_empty()) { + if print_doc || print_aliases { print!( "{:padding$}{}", "", @@ -453,30 +454,49 @@ impl Subcommand { ); } + let mut formatted_doc = String::new(); if print_doc { - print!(" "); let mut end = 0; for backtick in backtick_re().find_iter(doc) { let prefix = &doc[end..backtick.start()]; if !prefix.is_empty() { - print!("{}", color.doc().paint(prefix)); + formatted_doc.push_str(&format!("{}", color.doc().paint(prefix))); } - print!("{}", color.doc_backtick().paint(backtick.as_str())); + formatted_doc.push_str(&format!( + "{}", + color.doc_backtick().paint(backtick.as_str()) + )); end = backtick.end(); } let suffix = &doc[end..]; if !suffix.is_empty() { - print!("{}", color.doc().paint(suffix)); + formatted_doc.push_str(&format!("{}", color.doc().paint(suffix))); } } + let doc = print_doc.then_some(formatted_doc); + let aliases = print_aliases.then_some(format!( + "{}", + config + .color + .stdout() + .alias() + .paint(&format!("[aliases: {}]", aliases.join(", "))) + )); + + let (left, right) = if config.inline_aliases_left { + (aliases, doc) + } else { + (doc, aliases) + }; - if !aliases.is_empty() && !config.no_inline_aliases { + if print_doc || print_aliases { print!( " {}", - color - .alias() - .paint(&format!("[aliases: {}]", aliases.join(", "))) + [left, right] + .map(|s| s.unwrap_or_default()) + .join(" ") + .trim() ); } println!(); diff --git a/tests/list.rs b/tests/list.rs index 53a1c7372c..69afe9f362 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -474,3 +474,22 @@ fn unclosed_backticks() { ") .run(); } + +fn inline_aliases_left_flag() { + Test::new() + .justfile( + " + alias t := test1 + + # I'm a recipe + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--inline-aliases-left", "--list"]) + .stdout("Available recipes:\n test1 # [aliases: t] I'm a recipe\n test2\n") + .run(); +} From 040d0eae7eaa4830db7950571fa35bf501be6155 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Wed, 25 Sep 2024 16:12:53 -0400 Subject: [PATCH 13/28] Fix clippy error --- src/subcommand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index c8a0148ee9..ea83103e83 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -494,7 +494,7 @@ impl Subcommand { print!( " {}", [left, right] - .map(|s| s.unwrap_or_default()) + .map(Option::unwrap_or_default) .join(" ") .trim() ); From 04a854e9ee56fc48018e2f4e39ea87eb5b91ac43 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Tue, 8 Oct 2024 18:24:30 -0400 Subject: [PATCH 14/28] Switch to --alias-style flag --- src/alias_style.rs | 8 +++++ src/config.rs | 39 ++++++++++--------------- src/lib.rs | 2 ++ src/subcommand.rs | 6 ++-- tests/alias_style.rs | 60 ++++++++++++++++++++++++++++++++++++++ tests/lib.rs | 2 +- tests/list.rs | 19 ------------ tests/no_inline_aliases.rs | 20 ------------- 8 files changed, 90 insertions(+), 66 deletions(-) create mode 100644 src/alias_style.rs create mode 100644 tests/alias_style.rs delete mode 100644 tests/no_inline_aliases.rs diff --git a/src/alias_style.rs b/src/alias_style.rs new file mode 100644 index 0000000000..ade5b2fe88 --- /dev/null +++ b/src/alias_style.rs @@ -0,0 +1,8 @@ +use super::*; + +#[derive(Debug, PartialEq, Clone, ValueEnum)] +pub(crate) enum AliasStyle { + Inline, + InlineLeft, + Recipe, +} diff --git a/src/config.rs b/src/config.rs index d242c0613e..3264eba944 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,7 @@ use { #[derive(Debug, PartialEq)] pub(crate) struct Config { + pub(crate) alias_style: AliasStyle, pub(crate) allow_missing: bool, pub(crate) check: bool, pub(crate) color: Color, @@ -22,14 +23,12 @@ pub(crate) struct Config { pub(crate) dump_format: DumpFormat, pub(crate) explain: bool, pub(crate) highlight: bool, - pub(crate) inline_aliases_left: bool, pub(crate) invocation_directory: PathBuf, pub(crate) list_heading: String, pub(crate) list_prefix: String, 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) one: bool, pub(crate) search_config: SearchConfig, @@ -88,6 +87,7 @@ mod cmd { } mod arg { + pub(crate) const ALIAS_STYLE: &str = "ALIAS_STYLE"; pub(crate) const ALLOW_MISSING: &str = "ALLOW-MISSING"; pub(crate) const ARGUMENTS: &str = "ARGUMENTS"; pub(crate) const CHECK: &str = "CHECK"; @@ -102,7 +102,6 @@ mod arg { pub(crate) const EXPLAIN: &str = "EXPLAIN"; pub(crate) const GLOBAL_JUSTFILE: &str = "GLOBAL-JUSTFILE"; pub(crate) const HIGHLIGHT: &str = "HIGHLIGHT"; - pub(crate) const INLINE_ALIASES_LEFT: &str = "INLINE-ALIASES-LEFT"; pub(crate) const JUSTFILE: &str = "JUSTFILE"; pub(crate) const LIST_HEADING: &str = "LIST-HEADING"; pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX"; @@ -111,7 +110,6 @@ mod arg { pub(crate) const NO_DEPS: &str = "NO-DEPS"; pub(crate) const NO_DOTENV: &str = "NO-DOTENV"; pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT"; - pub(crate) const NO_INLINE_ALIASES: &str = "NO-INLINE-ALIASES"; pub(crate) const ONE: &str = "ONE"; pub(crate) const QUIET: &str = "QUIET"; pub(crate) const SET: &str = "SET"; @@ -149,6 +147,16 @@ impl Config { .usage(AnsiColor::Yellow.on_default() | Effects::BOLD) .valid(AnsiColor::Green.on_default()), ) + .arg( + Arg::new(arg::ALIAS_STYLE) + .long("alias-style") + .env("JUST_ALIAS_STYLE") + .action(ArgAction::Set) + .value_parser(clap::value_parser!(AliasStyle)) + .default_value("inline") + .help("Set the style that the list command will display aliases") + .conflicts_with(arg::NO_ALIASES), + ) .arg( Arg::new(arg::CHECK) .long("check") @@ -248,15 +256,6 @@ impl Config { .help("Highlight echoed recipe lines in bold") .overrides_with(arg::NO_HIGHLIGHT), ) - .arg( - Arg::new(arg::INLINE_ALIASES_LEFT) - .long("inline-aliases-left") - .env("JUST_INLINE_ALIASES_LEFT") - .action(ArgAction::SetTrue) - .help("Display inlined recipe aliases to the left of their doc in listing") - .conflicts_with(arg::NO_ALIASES) - .conflicts_with(arg::NO_INLINE_ALIASES), - ) .arg( Arg::new(arg::JUSTFILE) .short('f') @@ -299,14 +298,6 @@ 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") - .conflicts_with(arg::NO_ALIASES), - ) .arg( Arg::new(arg::NO_DEPS) .long("no-deps") @@ -760,6 +751,10 @@ impl Config { let explain = matches.get_flag(arg::EXPLAIN); Ok(Self { + alias_style: matches + .get_one::(arg::ALIAS_STYLE) + .unwrap() + .clone(), allow_missing: matches.get_flag(arg::ALLOW_MISSING), check: matches.get_flag(arg::CHECK), color: (*matches.get_one::(arg::COLOR).unwrap()).into(), @@ -778,14 +773,12 @@ impl Config { .clone(), explain, highlight: !matches.get_flag(arg::NO_HIGHLIGHT), - inline_aliases_left: matches.get_flag(arg::INLINE_ALIASES_LEFT), invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?, list_heading: matches.get_one::(arg::LIST_HEADING).unwrap().into(), list_prefix: matches.get_one::(arg::LIST_PREFIX).unwrap().into(), 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), one: matches.get_flag(arg::ONE), search_config, diff --git a/src/lib.rs b/src/lib.rs index 7ce669ea1a..30777e513d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ pub(crate) use { crate::{ alias::Alias, + alias_style::AliasStyle, analyzer::Analyzer, argument_parser::ArgumentParser, assignment::Assignment, @@ -179,6 +180,7 @@ pub mod summary; pub mod request; mod alias; +mod alias_style; mod analyzer; mod argument_parser; mod assignment; diff --git a/src/subcommand.rs b/src/subcommand.rs index ea83103e83..cc1f56ceff 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -442,7 +442,7 @@ impl Subcommand { ) { let doc = doc.unwrap_or_default(); let print_doc = !doc.is_empty() && doc.lines().count() <= 1; - let print_aliases = !config.no_inline_aliases && !aliases.is_empty(); + let print_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); let color = config.color.stdout(); if print_doc || print_aliases { @@ -484,7 +484,7 @@ impl Subcommand { .paint(&format!("[aliases: {}]", aliases.join(", "))) )); - let (left, right) = if config.inline_aliases_left { + let (left, right) = if config.alias_style == AliasStyle::InlineLeft { (aliases, doc) } else { (doc, aliases) @@ -622,7 +622,7 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { - let recipe_alias_entries = if config.no_inline_aliases { + let recipe_alias_entries = if config.alias_style == AliasStyle::Recipe { aliases.get(recipe.name()) } else { None diff --git a/tests/alias_style.rs b/tests/alias_style.rs new file mode 100644 index 0000000000..1b2f94b286 --- /dev/null +++ b/tests/alias_style.rs @@ -0,0 +1,60 @@ +use super::*; + +#[test] +fn alias_style_inline() { + Test::new() + .justfile( + " + alias t := test1 + + # A test recipe + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=inline", "--list"]) + .stdout("Available recipes:\n test1 # A test recipe [aliases: t]\n test2\n") + .run(); +} + +#[test] +fn alias_style_inline_left() { + Test::new() + .justfile( + " + alias t := test1 + + # A test recipe + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=inline-left", "--list"]) + .stdout("Available recipes:\n test1 # [aliases: t] A test recipe\n test2\n") + .run(); +} + +#[test] +fn alias_style_recipe() { + Test::new() + .justfile( + " + alias t := test1 + + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--alias-style=recipe", "--list"]) + .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") + .run(); +} diff --git a/tests/lib.rs b/tests/lib.rs index e719c31af1..a86a3da769 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -36,6 +36,7 @@ fn default() -> T { #[macro_use] mod test; +mod alias_style; mod allow_duplicate_recipes; mod allow_duplicate_variables; mod allow_missing; @@ -89,7 +90,6 @@ mod no_aliases; mod no_cd; mod no_dependencies; mod no_exit_message; -mod no_inline_aliases; mod os_attributes; mod parameters; mod parser; diff --git a/tests/list.rs b/tests/list.rs index 69afe9f362..53a1c7372c 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -474,22 +474,3 @@ fn unclosed_backticks() { ") .run(); } - -fn inline_aliases_left_flag() { - Test::new() - .justfile( - " - alias t := test1 - - # I'm a recipe - test1: - @echo 'test1' - - test2: - @echo 'test2' - ", - ) - .args(["--inline-aliases-left", "--list"]) - .stdout("Available recipes:\n test1 # [aliases: t] I'm a recipe\n test2\n") - .run(); -} diff --git a/tests/no_inline_aliases.rs b/tests/no_inline_aliases.rs deleted file mode 100644 index 4194933777..0000000000 --- a/tests/no_inline_aliases.rs +++ /dev/null @@ -1,20 +0,0 @@ -use super::*; - -#[test] -fn no_inline_aliases_flag() { - Test::new() - .justfile( - " - alias t := test1 - - test1: - @echo 'test1' - - test2: - @echo 'test2' - ", - ) - .args(["--no-inline-aliases", "--list"]) - .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") - .run(); -} From b199d572c7e9d023c557a0b701f1401d9ea43bc5 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Thu, 12 Dec 2024 10:07:20 -0500 Subject: [PATCH 15/28] Clean up backtick/doc coloring code --- src/subcommand.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index cc1f56ceff..075f222afc 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -454,27 +454,28 @@ impl Subcommand { ); } - let mut formatted_doc = String::new(); - if print_doc { + let doc = if print_doc { + let mut parts = vec![]; let mut end = 0; for backtick in backtick_re().find_iter(doc) { let prefix = &doc[end..backtick.start()]; if !prefix.is_empty() { - formatted_doc.push_str(&format!("{}", color.doc().paint(prefix))); + parts.push(color.doc().paint(prefix)); } - formatted_doc.push_str(&format!( - "{}", - color.doc_backtick().paint(backtick.as_str()) - )); + parts.push(color.doc_backtick().paint(backtick.as_str())); end = backtick.end(); } let suffix = &doc[end..]; if !suffix.is_empty() { - formatted_doc.push_str(&format!("{}", color.doc().paint(suffix))); + parts.push(color.doc().paint(suffix)); } - } - let doc = print_doc.then_some(formatted_doc); + + Some(parts.into_iter().map(|p| p.to_string()).collect::()) + } else { + None + }; + let aliases = print_aliases.then_some(format!( "{}", config From b9abcbd618ff7c813153cd49b477f879b21bd897 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 13:25:12 -0800 Subject: [PATCH 16/28] Avoid Vec::new() --- src/subcommand.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 075f222afc..24d5518b59 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -660,7 +660,10 @@ impl Subcommand { config, name, doc.as_deref(), - aliases.get(recipe.name()).unwrap_or(&Vec::new()), + aliases + .get(recipe.name()) + .map(Vec::as_slice) + .unwrap_or_default(), max_signature_width, &signature_widths, ); @@ -683,7 +686,7 @@ impl Subcommand { config, submodule.name(), submodule.doc.as_deref(), - &Vec::new(), + &[], max_signature_width, &signature_widths, ); From 0b518b2b3b2c07825cc0848251b9118a7aa9d277 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 13:29:59 -0800 Subject: [PATCH 17/28] Tweak help text --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 3264eba944..39b1bf7ab1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -154,7 +154,7 @@ impl Config { .action(ArgAction::Set) .value_parser(clap::value_parser!(AliasStyle)) .default_value("inline") - .help("Set the style that the list command will display aliases") + .help("Set list alias display style") .conflicts_with(arg::NO_ALIASES), ) .arg( From 7df991d000a0703449343a5f56afc22ee79738e9 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 13:32:53 -0800 Subject: [PATCH 18/28] Sort color functions --- src/color.rs | 126 +++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/src/color.rs b/src/color.rs index b6fdcfc435..723dcf615d 100644 --- a/src/color.rs +++ b/src/color.rs @@ -12,27 +12,16 @@ pub(crate) struct Color { } impl Color { - fn restyle(self, style: Style) -> Self { - Self { style, ..self } - } - - fn redirect(self, stream: impl IsTerminal) -> Self { - Self { - is_terminal: stream.is_terminal(), - ..self - } - } - - fn effective_style(&self) -> Style { - if self.active() { - self.style - } else { - Style::new() + pub(crate) fn active(&self) -> bool { + match self.use_color { + UseColor::Always => true, + UseColor::Never => false, + UseColor::Auto => self.is_terminal, } } - pub(crate) fn auto() -> Self { - Self::default() + pub(crate) fn alias(self) -> Self { + self.restyle(Style::new().fg(Purple)) } pub(crate) fn always() -> Self { @@ -42,25 +31,38 @@ impl Color { } } - pub(crate) fn never() -> Self { - Self { - use_color: UseColor::Never, - ..Self::default() - } + pub(crate) fn annotation(self) -> Self { + self.restyle(Style::new().fg(Purple)) } - pub(crate) fn stderr(self) -> Self { - self.redirect(io::stderr()) + pub(crate) fn auto() -> Self { + Self::default() } - pub(crate) fn stdout(self) -> Self { - self.redirect(io::stdout()) + pub(crate) fn banner(self) -> Self { + self.restyle(Style::new().fg(Cyan).bold()) + } + + pub(crate) fn command(self, foreground: Option) -> Self { + self.restyle(Style { + foreground, + is_bold: true, + ..Style::default() + }) } pub(crate) fn context(self) -> Self { self.restyle(Style::new().fg(Blue).bold()) } + pub(crate) fn diff_added(self) -> Self { + self.restyle(Style::new().fg(Green)) + } + + pub(crate) fn diff_deleted(self) -> Self { + self.restyle(Style::new().fg(Red)) + } + pub(crate) fn doc(self) -> Self { self.restyle(Style::new().fg(Blue)) } @@ -69,8 +71,12 @@ impl Color { self.restyle(Style::new().fg(Cyan)) } - pub(crate) fn alias(self) -> Self { - self.restyle(Style::new().fg(Purple)) + fn effective_style(&self) -> Style { + if self.active() { + self.style + } else { + Style::new() + } } pub(crate) fn error(self) -> Self { @@ -81,65 +87,59 @@ impl Color { self.restyle(Style::new().fg(Yellow).bold()) } - pub(crate) fn warning(self) -> Self { - self.restyle(Style::new().fg(Yellow).bold()) + pub(crate) fn message(self) -> Self { + self.restyle(Style::new().bold()) } - pub(crate) fn banner(self) -> Self { - self.restyle(Style::new().fg(Cyan).bold()) + pub(crate) fn never() -> Self { + Self { + use_color: UseColor::Never, + ..Self::default() + } } - pub(crate) fn command(self, foreground: Option) -> Self { - self.restyle(Style { - foreground, - is_bold: true, - ..Style::default() - }) + pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> { + self.effective_style().paint(text) } pub(crate) fn parameter(self) -> Self { self.restyle(Style::new().fg(Cyan)) } - pub(crate) fn message(self) -> Self { - self.restyle(Style::new().bold()) - } - - pub(crate) fn annotation(self) -> Self { - self.restyle(Style::new().fg(Purple)) - } - - pub(crate) fn string(self) -> Self { - self.restyle(Style::new().fg(Green)) + pub(crate) fn prefix(&self) -> Prefix { + self.effective_style().prefix() } - pub(crate) fn diff_added(self) -> Self { - self.restyle(Style::new().fg(Green)) + fn redirect(self, stream: impl IsTerminal) -> Self { + Self { + is_terminal: stream.is_terminal(), + ..self + } } - pub(crate) fn diff_deleted(self) -> Self { - self.restyle(Style::new().fg(Red)) + fn restyle(self, style: Style) -> Self { + Self { style, ..self } } - pub(crate) fn active(&self) -> bool { - match self.use_color { - UseColor::Always => true, - UseColor::Never => false, - UseColor::Auto => self.is_terminal, - } + pub(crate) fn stderr(self) -> Self { + self.redirect(io::stderr()) } - pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> { - self.effective_style().paint(text) + pub(crate) fn stdout(self) -> Self { + self.redirect(io::stdout()) } - pub(crate) fn prefix(&self) -> Prefix { - self.effective_style().prefix() + pub(crate) fn string(self) -> Self { + self.restyle(Style::new().fg(Green)) } pub(crate) fn suffix(&self) -> Suffix { self.effective_style().suffix() } + + pub(crate) fn warning(self) -> Self { + self.restyle(Style::new().fg(Yellow).bold()) + } } impl From for Color { From faf4ae46b1205d41a59bb0290c24fe409c697e96 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 13:34:43 -0800 Subject: [PATCH 19/28] Modify --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 39b1bf7ab1..20d3f44bdb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -154,7 +154,7 @@ impl Config { .action(ArgAction::Set) .value_parser(clap::value_parser!(AliasStyle)) .default_value("inline") - .help("Set list alias display style") + .help("Set list command alias display style") .conflicts_with(arg::NO_ALIASES), ) .arg( From 918cc2b68e12bff655dc8ae099cbb20178f70b9c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:06:53 -0800 Subject: [PATCH 20/28] Tweak tests --- tests/alias_style.rs | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/tests/alias_style.rs b/tests/alias_style.rs index 1b2f94b286..e4ad6f240f 100644 --- a/tests/alias_style.rs +++ b/tests/alias_style.rs @@ -5,18 +5,22 @@ fn alias_style_inline() { Test::new() .justfile( " - alias t := test1 + alias f := foo - # A test recipe - test1: - @echo 'test1' + # comment + foo: - test2: - @echo 'test2' + bar: ", ) .args(["--alias-style=inline", "--list"]) - .stdout("Available recipes:\n test1 # A test recipe [aliases: t]\n test2\n") + .stdout( + " + Available recipes: + bar + foo # comment [aliases: f] + ", + ) .run(); } @@ -25,18 +29,22 @@ fn alias_style_inline_left() { Test::new() .justfile( " - alias t := test1 + alias f := foo - # A test recipe - test1: - @echo 'test1' + # comment + foo: - test2: - @echo 'test2' + bar: ", ) .args(["--alias-style=inline-left", "--list"]) - .stdout("Available recipes:\n test1 # [aliases: t] A test recipe\n test2\n") + .stdout( + " + Available recipes: + bar + foo # [aliases: f] comment + ", + ) .run(); } @@ -45,16 +53,22 @@ fn alias_style_recipe() { Test::new() .justfile( " - alias t := test1 + alias f := foo - test1: - @echo 'test1' + # comment + foo: - test2: - @echo 'test2' + bar: ", ) .args(["--alias-style=recipe", "--list"]) - .stdout("Available recipes:\n test1\n t # alias for `test1`\n test2\n") + .stdout( + " + Available recipes: + bar + foo # comment + f # alias for `foo` + ", + ) .run(); } From 952c952408a9ccb60678ff71a3500b92f5731750 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:12:58 -0800 Subject: [PATCH 21/28] Add default and multiple tests --- src/subcommand.rs | 10 ++++---- tests/alias_style.rs | 59 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 24d5518b59..c1c08f1a5a 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -478,11 +478,11 @@ impl Subcommand { let aliases = print_aliases.then_some(format!( "{}", - config - .color - .stdout() - .alias() - .paint(&format!("[aliases: {}]", aliases.join(", "))) + config.color.stdout().alias().paint(&format!( + "[alias{}: {}]", + if aliases.len() == 1 { "" } else { "es" }, + aliases.join(", ") + )) )); let (left, right) = if config.alias_style == AliasStyle::InlineLeft { diff --git a/tests/alias_style.rs b/tests/alias_style.rs index e4ad6f240f..7dac59d626 100644 --- a/tests/alias_style.rs +++ b/tests/alias_style.rs @@ -1,7 +1,56 @@ use super::*; #[test] -fn alias_style_inline() { +fn default() { + Test::new() + .justfile( + " + alias f := foo + + # comment + foo: + + bar: + ", + ) + .args(["--list"]) + .stdout( + " + Available recipes: + bar + foo # comment [alias: f] + ", + ) + .run(); +} + +#[test] +fn multiple() { + Test::new() + .justfile( + " + alias a := foo + alias b := foo + + # comment + foo: + + bar: + ", + ) + .args(["--list"]) + .stdout( + " + Available recipes: + bar + foo # comment [aliases: a, b] + ", + ) + .run(); +} + +#[test] +fn inline() { Test::new() .justfile( " @@ -18,14 +67,14 @@ fn alias_style_inline() { " Available recipes: bar - foo # comment [aliases: f] + foo # comment [alias: f] ", ) .run(); } #[test] -fn alias_style_inline_left() { +fn inline_left() { Test::new() .justfile( " @@ -42,14 +91,14 @@ fn alias_style_inline_left() { " Available recipes: bar - foo # [aliases: f] comment + foo # [alias: f] comment ", ) .run(); } #[test] -fn alias_style_recipe() { +fn recipe() { Test::new() .justfile( " From 9cfb270197010a095b35f16e0eb85b30b45f0a23 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:13:47 -0800 Subject: [PATCH 22/28] Revise --- src/subcommand.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/subcommand.rs b/src/subcommand.rs index c1c08f1a5a..be6f4b5b55 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -500,6 +500,7 @@ impl Subcommand { .trim() ); } + println!(); } From ae8ebabcbf360c836c1fc4f59ad1629514d3990a Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:15:21 -0800 Subject: [PATCH 23/28] Fix tests --- tests/misc.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/misc.rs b/tests/misc.rs index 3187724e88..9e07f147c5 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -11,7 +11,7 @@ test! { args: ("--list"), stdout: " Available recipes: - foo # [aliases: f] + foo # [alias: f] ", } @@ -31,7 +31,7 @@ fn alias_listing_with_doc() { .stdout( " Available recipes: - foo # foo command [aliases: f] + foo # foo command [alias: f] ", ) .status(EXIT_SUCCESS) @@ -54,7 +54,7 @@ test! { args: ("--list"), stdout: " Available recipes: - foo PARAM='foo' # [aliases: f] + foo PARAM='foo' # [alias: f] ", } @@ -946,7 +946,7 @@ a: stdout: r" Available recipes: a - b # [aliases: c] + b # [alias: c] ", } @@ -960,7 +960,7 @@ a: args: ("--list", "--unsorted"), stdout: r" Available recipes: - b # [aliases: c] + b # [alias: c] a ", } From eb3d68a27b8d18d3039be8eac26e24f1a205bc0e Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:15:45 -0800 Subject: [PATCH 24/28] Revise --- tests/misc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/misc.rs b/tests/misc.rs index 9e07f147c5..79b609f314 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -34,7 +34,6 @@ fn alias_listing_with_doc() { foo # foo command [alias: f] ", ) - .status(EXIT_SUCCESS) .run(); } From 29737ca8ae00010146848333feaa31d07906d402 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 14:22:10 -0800 Subject: [PATCH 25/28] Use color variable --- src/subcommand.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index be6f4b5b55..7f798ed07e 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -449,7 +449,7 @@ impl Subcommand { print!( "{:padding$}{}", "", - config.color.stdout().doc().paint("#"), + color.doc().paint("#"), padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, ); } @@ -478,7 +478,7 @@ impl Subcommand { let aliases = print_aliases.then_some(format!( "{}", - config.color.stdout().alias().paint(&format!( + color.alias().paint(&format!( "[alias{}: {}]", if aliases.len() == 1 { "" } else { "es" }, aliases.join(", ") From 832c4250878dbed6cd36be3232dd086073eb6359 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:06:54 -0800 Subject: [PATCH 26/28] More tweaks --- src/analyzer.rs | 2 +- src/parser.rs | 2 +- src/subcommand.rs | 86 ++++++++++++++++++++++------------------------- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/analyzer.rs b/src/analyzer.rs index 1087bdeec9..e160d8bcb4 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -201,7 +201,7 @@ impl<'run, 'src> Analyzer<'run, 'src> { Rc::clone(next) }), }), - doc, + doc: doc.filter(|doc| !doc.is_empty()), groups: groups.into(), loaded: loaded.into(), modules: self.modules, diff --git a/src/parser.rs b/src/parser.rs index 5d7821a335..2258c13b3b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -952,7 +952,7 @@ impl<'run, 'src> Parser<'run, 'src> { attributes, body, dependencies, - doc, + doc: doc.filter(|doc| !doc.is_empty()), file_depth: self.file_depth, import_offsets: self.import_offsets.clone(), name, diff --git a/src/subcommand.rs b/src/subcommand.rs index 7f798ed07e..7f8270d6ee 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -432,7 +432,7 @@ impl Subcommand { } fn list_module(config: &Config, module: &Justfile, depth: usize) { - fn format_doc( + fn print_doc_and_aliases( config: &Config, name: &str, doc: Option<&str>, @@ -440,68 +440,64 @@ impl Subcommand { max_signature_width: usize, signature_widths: &BTreeMap<&str, usize>, ) { - let doc = doc.unwrap_or_default(); - let print_doc = !doc.is_empty() && doc.lines().count() <= 1; - let print_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); let color = config.color.stdout(); - if print_doc || print_aliases { - print!( - "{:padding$}{}", - "", - color.doc().paint("#"), - padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, - ); + let inline_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); + + if !inline_aliases && doc.is_none() { + println!(); + return; + } + + print!( + "{:padding$}{}", + "", + color.doc().paint("#"), + padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, + ); + + if inline_aliases { + if config.alias_style == AliasStyle::InlineLeft { + print_aliases(config, aliases); + } } - let doc = if print_doc { - let mut parts = vec![]; + if let Some(doc) = doc { + print!(" "); let mut end = 0; for backtick in backtick_re().find_iter(doc) { let prefix = &doc[end..backtick.start()]; if !prefix.is_empty() { - parts.push(color.doc().paint(prefix)); + print!("{}", color.doc().paint(prefix)); } - parts.push(color.doc_backtick().paint(backtick.as_str())); + print!("{}", color.doc_backtick().paint(backtick.as_str())); end = backtick.end(); } let suffix = &doc[end..]; if !suffix.is_empty() { - parts.push(color.doc().paint(suffix)); + print!("{}", color.doc().paint(suffix)); } + } - Some(parts.into_iter().map(|p| p.to_string()).collect::()) - } else { - None - }; + if inline_aliases { + if config.alias_style == AliasStyle::Inline { + print_aliases(config, aliases); + } + } - let aliases = print_aliases.then_some(format!( - "{}", - color.alias().paint(&format!( + println!(); + } + + fn print_aliases(config: &Config, aliases: &[&str]) { + print!( + " {}", + config.color.stdout().alias().paint(&format!( "[alias{}: {}]", if aliases.len() == 1 { "" } else { "es" }, aliases.join(", ") )) - )); - - let (left, right) = if config.alias_style == AliasStyle::InlineLeft { - (aliases, doc) - } else { - (doc, aliases) - }; - - if print_doc || print_aliases { - print!( - " {}", - [left, right] - .map(Option::unwrap_or_default) - .join(" ") - .trim() - ); - } - - println!(); + ); } let aliases = if config.no_aliases { @@ -657,10 +653,10 @@ impl Subcommand { RecipeSignature { name, recipe }.color_display(config.color.stdout()) ); - format_doc( + print_doc_and_aliases( config, name, - doc.as_deref(), + doc.filter(|doc| doc.lines().count() <= 1).as_deref(), aliases .get(recipe.name()) .map(Vec::as_slice) @@ -683,7 +679,7 @@ impl Subcommand { Self::list_module(config, submodule, depth + 1); } else { print!("{list_prefix}{} ...", submodule.name()); - format_doc( + print_doc_and_aliases( config, submodule.name(), submodule.doc.as_deref(), From 79bc9810d7c5e5121a36e550381ea3a72b5caa6d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:09:53 -0800 Subject: [PATCH 27/28] More ocd tweaking --- src/subcommand.rs | 49 ++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 7f8270d6ee..5b6169c8f6 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -444,22 +444,28 @@ impl Subcommand { let inline_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); - if !inline_aliases && doc.is_none() { - println!(); - return; + if inline_aliases || doc.is_some() { + print!( + "{:padding$}{}", + "", + color.doc().paint("#"), + padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, + ); } - print!( - "{:padding$}{}", - "", - color.doc().paint("#"), - padding = max_signature_width.saturating_sub(signature_widths[name]) + 1, - ); + let print_aliases = || { + print!( + " {}", + color.alias().paint(&format!( + "[alias{}: {}]", + if aliases.len() == 1 { "" } else { "es" }, + aliases.join(", ") + )) + ); + }; - if inline_aliases { - if config.alias_style == AliasStyle::InlineLeft { - print_aliases(config, aliases); - } + if inline_aliases && config.alias_style == AliasStyle::InlineLeft { + print_aliases(); } if let Some(doc) = doc { @@ -480,26 +486,13 @@ impl Subcommand { } } - if inline_aliases { - if config.alias_style == AliasStyle::Inline { - print_aliases(config, aliases); - } + if inline_aliases && config.alias_style == AliasStyle::Inline { + print_aliases(); } println!(); } - fn print_aliases(config: &Config, aliases: &[&str]) { - print!( - " {}", - config.color.stdout().alias().paint(&format!( - "[alias{}: {}]", - if aliases.len() == 1 { "" } else { "es" }, - aliases.join(", ") - )) - ); - } - let aliases = if config.no_aliases { BTreeMap::new() } else { From 8e61c03f46ce5f0e057394065672e9437c8e4ad3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 12 Dec 2024 15:34:16 -0800 Subject: [PATCH 28/28] Tweak names --- src/alias_style.rs | 6 +++--- src/config.rs | 2 +- src/subcommand.rs | 8 ++++---- tests/alias_style.rs | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/alias_style.rs b/src/alias_style.rs index ade5b2fe88..2f380d7c8f 100644 --- a/src/alias_style.rs +++ b/src/alias_style.rs @@ -2,7 +2,7 @@ use super::*; #[derive(Debug, PartialEq, Clone, ValueEnum)] pub(crate) enum AliasStyle { - Inline, - InlineLeft, - Recipe, + Left, + Right, + Separate, } diff --git a/src/config.rs b/src/config.rs index 20d3f44bdb..575e73cd1e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -153,7 +153,7 @@ impl Config { .env("JUST_ALIAS_STYLE") .action(ArgAction::Set) .value_parser(clap::value_parser!(AliasStyle)) - .default_value("inline") + .default_value("right") .help("Set list command alias display style") .conflicts_with(arg::NO_ALIASES), ) diff --git a/src/subcommand.rs b/src/subcommand.rs index 5b6169c8f6..fbb5cb0ba8 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -442,7 +442,7 @@ impl Subcommand { ) { let color = config.color.stdout(); - let inline_aliases = config.alias_style != AliasStyle::Recipe && !aliases.is_empty(); + let inline_aliases = config.alias_style != AliasStyle::Separate && !aliases.is_empty(); if inline_aliases || doc.is_some() { print!( @@ -464,7 +464,7 @@ impl Subcommand { ); }; - if inline_aliases && config.alias_style == AliasStyle::InlineLeft { + if inline_aliases && config.alias_style == AliasStyle::Left { print_aliases(); } @@ -486,7 +486,7 @@ impl Subcommand { } } - if inline_aliases && config.alias_style == AliasStyle::Inline { + if inline_aliases && config.alias_style == AliasStyle::Right { print_aliases(); } @@ -613,7 +613,7 @@ impl Subcommand { if let Some(recipes) = recipe_groups.get(&group) { for recipe in recipes { - let recipe_alias_entries = if config.alias_style == AliasStyle::Recipe { + let recipe_alias_entries = if config.alias_style == AliasStyle::Separate { aliases.get(recipe.name()) } else { None diff --git a/tests/alias_style.rs b/tests/alias_style.rs index 7dac59d626..dddea0d8ce 100644 --- a/tests/alias_style.rs +++ b/tests/alias_style.rs @@ -50,7 +50,7 @@ fn multiple() { } #[test] -fn inline() { +fn right() { Test::new() .justfile( " @@ -62,7 +62,7 @@ fn inline() { bar: ", ) - .args(["--alias-style=inline", "--list"]) + .args(["--alias-style=right", "--list"]) .stdout( " Available recipes: @@ -74,7 +74,7 @@ fn inline() { } #[test] -fn inline_left() { +fn left() { Test::new() .justfile( " @@ -86,7 +86,7 @@ fn inline_left() { bar: ", ) - .args(["--alias-style=inline-left", "--list"]) + .args(["--alias-style=left", "--list"]) .stdout( " Available recipes: @@ -98,7 +98,7 @@ fn inline_left() { } #[test] -fn recipe() { +fn separate() { Test::new() .justfile( " @@ -110,7 +110,7 @@ fn recipe() { bar: ", ) - .args(["--alias-style=recipe", "--list"]) + .args(["--alias-style=separate", "--list"]) .stdout( " Available recipes: