Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show submodule recipes in --choose #2069

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/namepath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ impl<'src> Namepath<'src> {
}
}

impl<'str> Serialize for Namepath<'str> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut path = String::new();

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 {
path.push_str("::");
write!(f, "::")?;
}
path.push_str(name.lexeme());
write!(f, "{name}")?;
}
Ok(())
}
}

serializer.serialize_str(&path)
impl<'src> Serialize for Namepath<'src> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{self}"))
}
}
19 changes: 12 additions & 7 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
}
Expand Down
17 changes: 17 additions & 0 deletions tests/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down