Show submodule recipes in --choose (#2069)

This commit is contained in:
Casey Rodarmor 2024-05-20 23:22:56 -07:00 committed by GitHub
parent 77f343e7b1
commit 324c5d3113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 18 deletions

View File

@ -9,20 +9,23 @@ impl<'src> Namepath<'src> {
} }
} }
impl<'str> Serialize for Namepath<'str> { impl<'src> Display for Namepath<'src> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
for (i, name) in self.0.iter().enumerate() {
if i > 0 {
write!(f, "::")?;
}
write!(f, "{name}")?;
}
Ok(())
}
}
impl<'src> Serialize for Namepath<'src> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
let mut path = String::new(); serializer.serialize_str(&format!("{self}"))
for (i, name) in self.0.iter().enumerate() {
if i > 0 {
path.push_str("::");
}
path.push_str(name.lexeme());
}
serializer.serialize_str(&path)
} }
} }

View File

@ -209,12 +209,17 @@ impl Subcommand {
overrides: &BTreeMap<String, String>, overrides: &BTreeMap<String, String>,
chooser: Option<&str>, chooser: Option<&str>,
) -> Result<(), Error<'src>> { ) -> Result<(), Error<'src>> {
let recipes = justfile let mut recipes = Vec::<&Recipe<Dependency>>::new();
.public_recipes(config.unsorted) let mut stack = vec![justfile];
.iter() while let Some(module) = stack.pop() {
.filter(|recipe| recipe.min_arguments() == 0) recipes.extend(
.copied() module
.collect::<Vec<&Recipe<Dependency>>>(); .public_recipes(config.unsorted)
.iter()
.filter(|recipe| recipe.min_arguments() == 0),
);
stack.extend(module.modules.values());
}
if recipes.is_empty() { if recipes.is_empty() {
return Err(Error::NoChoosableRecipes); return Err(Error::NoChoosableRecipes);
@ -249,7 +254,7 @@ impl Subcommand {
.stdin .stdin
.as_mut() .as_mut()
.expect("Child was created with piped stdio") .expect("Child was created with piped stdio")
.write_all(format!("{}\n", recipe.name).as_bytes()) .write_all(format!("{}\n", recipe.namepath).as_bytes())
{ {
return Err(Error::ChooserWrite { io_error, chooser }); return Err(Error::ChooserWrite { io_error, chooser });
} }

View File

@ -80,6 +80,23 @@ fn skip_private_recipes() {
.run(); .run();
} }
#[test]
fn recipes_in_submodules_can_be_chosen() {
Test::new()
.args(["--unstable", "--choose"])
.env("JUST_CHOOSER", "head -n10")
.write("bar.just", "baz:\n echo BAZ")
.test_round_trip(false)
.justfile(
"
mod bar
",
)
.stderr("echo BAZ\n")
.stdout("BAZ\n")
.run();
}
#[test] #[test]
fn skip_recipes_that_require_arguments() { fn skip_recipes_that_require_arguments() {
Test::new() Test::new()