From d2b10e04d3b6eb74ffbbb20f21dc44ca61cf8c53 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 30 May 2024 12:24:06 -0500 Subject: [PATCH] Use space-separated recipe paths in `--choose` (#2115) --- src/namepath.rs | 7 +++++++ src/subcommand.rs | 17 +++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/namepath.rs b/src/namepath.rs index 6d4a798..c896b36 100644 --- a/src/namepath.rs +++ b/src/namepath.rs @@ -7,6 +7,13 @@ impl<'src> Namepath<'src> { pub(crate) fn join(&self, name: Name<'src>) -> Self { Self(self.0.iter().copied().chain(iter::once(name)).collect()) } + + pub(crate) fn spaced(&self) -> ModulePath { + ModulePath { + path: self.0.iter().map(|name| name.lexeme().into()).collect(), + spaced: true, + } + } } impl<'src> Display for Namepath<'src> { diff --git a/src/subcommand.rs b/src/subcommand.rs index c2ec213..09aacbe 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -261,14 +261,15 @@ impl Subcommand { }; for recipe in recipes { - if let Err(io_error) = child - .stdin - .as_mut() - .expect("Child was created with piped stdio") - .write_all(format!("{}\n", recipe.namepath).as_bytes()) - { - return Err(Error::ChooserWrite { io_error, chooser }); - } + writeln!( + child.stdin.as_mut().unwrap(), + "{}", + recipe.namepath.spaced() + ) + .map_err(|io_error| Error::ChooserWrite { + io_error, + chooser: chooser.clone(), + })?; } let output = match child.wait_with_output() {