From dfdf075e3d9f4770e71342ba44bd21a199b68269 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 8 Jun 2024 17:00:18 +0200 Subject: [PATCH 1/3] refactor --- src/config.rs | 8 -------- src/subcommand.rs | 10 +++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/config.rs b/src/config.rs index d2056d5d3e..4efdf46962 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,14 +11,6 @@ const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary choo If `--chooser` is not passed the chooser defaults to the \ value of $JUST_CHOOSER, falling back to `fzf`"; -pub(crate) fn chooser_default(justfile: &Path) -> OsString { - let mut chooser = OsString::new(); - chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \""); - chooser.push(justfile); - chooser.push("\" --show {}'"); - chooser -} - #[derive(Debug, PartialEq)] pub(crate) struct Config { pub(crate) check: bool, diff --git a/src/subcommand.rs b/src/subcommand.rs index e1433154d1..450ffa3353 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -231,7 +231,15 @@ impl Subcommand { return Err(Error::NoChoosableRecipes); } - let chooser = chooser.map_or_else(|| config::chooser_default(&search.justfile), From::from); + let chooser = if let Some(chooser) = chooser { + OsString::from(chooser) + } else { + let mut chooser = OsString::new(); + chooser.push("fzf --multi --preview 'just --unstable --color always --justfile \""); + chooser.push(&search.justfile); + chooser.push("\" --show {}'"); + chooser + }; let result = justfile .settings From 8b966017976d8a61d234dd871a864815573f7a00 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 9 Jun 2024 02:57:17 +0200 Subject: [PATCH 2/3] Amend --- src/config.rs | 17 ++++++++++++----- tests/show.rs | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4efdf46962..c2d6dea70d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -560,15 +560,20 @@ impl Config { } } - fn parse_module_path(path: ValuesRef) -> ConfigResult { + fn parse_module_path(values: ValuesRef) -> ConfigResult { + let path = values.clone().map(|s| (*s).as_str()).collect::>(); + + let path = if path.len() == 1 && path[0].contains(' ') { + path[0].split_whitespace().collect::>() + } else { + path + }; + path - .clone() - .map(|s| (*s).as_str()) - .collect::>() .as_slice() .try_into() .map_err(|()| ConfigError::ModulePath { - path: path.cloned().collect(), + path: values.cloned().collect(), }) } @@ -698,6 +703,8 @@ impl Config { } else if matches.get_flag(cmd::MAN) { Subcommand::Man } else if let Some(path) = matches.get_many::(cmd::SHOW) { + // if path is a single string and contains spaces, split it + Subcommand::Show { path: Self::parse_module_path(path)?, } diff --git a/tests/show.rs b/tests/show.rs index e9fe5e6a97..17aaa473db 100644 --- a/tests/show.rs +++ b/tests/show.rs @@ -124,3 +124,18 @@ fn show_invalid_path() { .status(1) .run(); } + +#[test] +fn show_space_separated_path() { + Test::new() + .write("foo.just", "bar:\n @echo MODULE") + .justfile( + " + mod foo + ", + ) + .test_round_trip(false) + .args(["--unstable", "--show", "foo bar"]) + .stdout("bar:\n @echo MODULE\n") + .run(); +} From dd70c59887d720c301d15db8279c7ef3f85f7d11 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 9 Jun 2024 02:58:27 +0200 Subject: [PATCH 3/3] Enhance --- src/config.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index c2d6dea70d..34b72f3830 100644 --- a/src/config.rs +++ b/src/config.rs @@ -703,8 +703,6 @@ impl Config { } else if matches.get_flag(cmd::MAN) { Subcommand::Man } else if let Some(path) = matches.get_many::(cmd::SHOW) { - // if path is a single string and contains spaces, split it - Subcommand::Show { path: Self::parse_module_path(path)?, }