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>
where
S: Serializer,
{
let mut path = String::new();
for (i, name) in self.0.iter().enumerate() {
if i > 0 {
path.push_str("::");
}
path.push_str(name.lexeme());
}
serializer.serialize_str(&path)
serializer.serialize_str(&format!("{self}"))
}
}

View File

@ -209,12 +209,17 @@ impl Subcommand {
overrides: &BTreeMap<String, String>,
chooser: Option<&str>,
) -> Result<(), Error<'src>> {
let recipes = justfile
.public_recipes(config.unsorted)
.iter()
.filter(|recipe| recipe.min_arguments() == 0)
.copied()
.collect::<Vec<&Recipe<Dependency>>>();
let mut recipes = Vec::<&Recipe<Dependency>>::new();
let mut stack = vec![justfile];
while let Some(module) = stack.pop() {
recipes.extend(
module
.public_recipes(config.unsorted)
.iter()
.filter(|recipe| recipe.min_arguments() == 0),
);
stack.extend(module.modules.values());
}
if recipes.is_empty() {
return Err(Error::NoChoosableRecipes);
@ -249,7 +254,7 @@ impl Subcommand {
.stdin
.as_mut()
.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 });
}

View File

@ -80,6 +80,23 @@ fn skip_private_recipes() {
.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]
fn skip_recipes_that_require_arguments() {
Test::new()