cli: add helper function that makes Command builder from CommandArgs

This commit is contained in:
Yuya Nishihara 2022-12-01 21:32:58 +09:00
parent 368aa06fdc
commit f23302bc53
2 changed files with 11 additions and 4 deletions

View file

@ -2375,10 +2375,8 @@ fn edit_description(
.config() .config()
.get("ui.editor") .get("ui.editor")
.unwrap_or_else(|_| "pico".into()); .unwrap_or_else(|_| "pico".into());
let args = editor.args(); let exit_status = editor
let editor_args = if args.len() > 1 { &args[1..] } else { &[] }; .to_command()
let exit_status = std::process::Command::new(&args[0])
.args(editor_args)
.arg(&description_file_path) .arg(&description_file_path)
.status() .status()
.map_err(|_| user_error(format!("Failed to run editor '{editor}'")))?; .map_err(|_| user_error(format!("Failed to run editor '{editor}'")))?;

View file

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command;
use std::{env, fmt}; use std::{env, fmt};
use jujutsu_lib::settings::UserSettings; use jujutsu_lib::settings::UserSettings;
@ -147,6 +148,14 @@ impl FullCommandArgs {
FullCommandArgs::String(s) => s.split(' ').map(|s| s.to_owned()).collect(), FullCommandArgs::String(s) => s.split(' ').map(|s| s.to_owned()).collect(),
} }
} }
/// Returns process builder configured with this.
pub fn to_command(&self) -> Command {
let full_args = self.args();
let mut cmd = Command::new(&full_args[0]);
cmd.args(&full_args[1..]);
cmd
}
} }
impl<T: AsRef<str> + ?Sized> From<&T> for FullCommandArgs { impl<T: AsRef<str> + ?Sized> From<&T> for FullCommandArgs {