diff --git a/src/cli_util.rs b/src/cli_util.rs index 25459d1c7..734033b94 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -56,7 +56,7 @@ use jujutsu_lib::{dag_walk, file_util, git, revset}; use thiserror::Error; use tracing_subscriber::prelude::*; -use crate::config::{AnnotatedValue, FullCommandArgs, LayeredConfigs}; +use crate::config::{AnnotatedValue, CommandNameAndArgs, LayeredConfigs}; use crate::formatter::{Formatter, PlainTextFormatter}; use crate::merge_tools::{ConflictResolveError, DiffEditError}; use crate::template_parser::{self, TemplateParseError}; @@ -1557,7 +1557,7 @@ pub fn serialize_config_value(value: &config::Value) -> String { } pub fn run_ui_editor(settings: &UserSettings, edit_path: &PathBuf) -> Result<(), CommandError> { - let editor: FullCommandArgs = settings + let editor: CommandNameAndArgs = settings .config() .get("ui.editor") .unwrap_or_else(|_| "pico".into()); diff --git a/src/config.rs b/src/config.rs index fb961a83b..115d84df9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -325,23 +325,23 @@ fn read_config_path(config_path: &Path) -> Result (Cow, Cow<[String]>) { match self { - FullCommandArgs::String(s) => { + CommandNameAndArgs::String(s) => { // Handle things like `EDITOR=emacs -nw` (TODO: parse shell escapes) let mut args = s.split(' ').map(|s| s.to_owned()); (args.next().unwrap().into(), args.collect()) } - FullCommandArgs::Vec(NonEmptyCommandArgsVec(a)) => { + CommandNameAndArgs::Vec(NonEmptyCommandArgsVec(a)) => { (Cow::Borrowed(&a[0]), Cow::Borrowed(&a[1..])) } } @@ -356,18 +356,18 @@ impl FullCommandArgs { } } -impl + ?Sized> From<&T> for FullCommandArgs { +impl + ?Sized> From<&T> for CommandNameAndArgs { fn from(s: &T) -> Self { - FullCommandArgs::String(s.as_ref().to_owned()) + CommandNameAndArgs::String(s.as_ref().to_owned()) } } -impl fmt::Display for FullCommandArgs { +impl fmt::Display for CommandNameAndArgs { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - FullCommandArgs::String(s) => write!(f, "{s}"), + CommandNameAndArgs::String(s) => write!(f, "{s}"), // TODO: format with shell escapes - FullCommandArgs::Vec(a) => write!(f, "{}", a.0.join(" ")), + CommandNameAndArgs::Vec(a) => write!(f, "{}", a.0.join(" ")), } } } @@ -408,18 +408,18 @@ mod tests { .build() .unwrap(); - assert!(config.get::("empty_array").is_err()); + assert!(config.get::("empty_array").is_err()); - let command_args: FullCommandArgs = config.get("empty_string").unwrap(); - assert_eq!(command_args, FullCommandArgs::String("".to_owned())); + let command_args: CommandNameAndArgs = config.get("empty_string").unwrap(); + assert_eq!(command_args, CommandNameAndArgs::String("".to_owned())); let (name, args) = command_args.split_name_and_args(); assert_eq!(name, ""); assert!(args.is_empty()); - let command_args: FullCommandArgs = config.get("array").unwrap(); + let command_args: CommandNameAndArgs = config.get("array").unwrap(); assert_eq!( command_args, - FullCommandArgs::Vec(NonEmptyCommandArgsVec( + CommandNameAndArgs::Vec(NonEmptyCommandArgsVec( ["emacs", "-nw",].map(|s| s.to_owned()).to_vec() )) ); @@ -427,10 +427,10 @@ mod tests { assert_eq!(name, "emacs"); assert_eq!(args, ["-nw"].as_ref()); - let command_args: FullCommandArgs = config.get("string").unwrap(); + let command_args: CommandNameAndArgs = config.get("string").unwrap(); assert_eq!( command_args, - FullCommandArgs::String("emacs -nw".to_owned()) + CommandNameAndArgs::String("emacs -nw".to_owned()) ); let (name, args) = command_args.split_name_and_args(); assert_eq!(name, "emacs"); diff --git a/src/merge_tools.rs b/src/merge_tools.rs index 9a5315f42..2062b9539 100644 --- a/src/merge_tools.rs +++ b/src/merge_tools.rs @@ -35,7 +35,7 @@ use jujutsu_lib::tree::Tree; use jujutsu_lib::working_copy::{CheckoutError, SnapshotError, TreeState}; use thiserror::Error; -use crate::config::FullCommandArgs; +use crate::config::CommandNameAndArgs; use crate::ui::Ui; #[derive(Debug, Error)] @@ -408,7 +408,7 @@ struct MergeTool { } impl MergeTool { - pub fn with_edit_args(command_args: &FullCommandArgs) -> Self { + pub fn with_edit_args(command_args: &CommandNameAndArgs) -> Self { let (name, args) = command_args.split_name_and_args(); MergeTool { program: name.into_owned(), @@ -418,7 +418,7 @@ impl MergeTool { } } - pub fn with_merge_args(command_args: &FullCommandArgs) -> Self { + pub fn with_merge_args(command_args: &CommandNameAndArgs) -> Self { let (name, args) = command_args.split_name_and_args(); MergeTool { program: name.into_owned(), @@ -455,8 +455,8 @@ fn get_diff_editor_from_settings( ) -> Result { let args = editor_args_from_settings(ui, settings, "ui.diff-editor")?; let maybe_editor = match &args { - FullCommandArgs::String(name) => get_tool_config(settings, name)?, - FullCommandArgs::Vec(_) => None, + CommandNameAndArgs::String(name) => get_tool_config(settings, name)?, + CommandNameAndArgs::Vec(_) => None, }; Ok(maybe_editor.unwrap_or_else(|| MergeTool::with_edit_args(&args))) } @@ -467,8 +467,8 @@ fn get_merge_tool_from_settings( ) -> Result { let args = editor_args_from_settings(ui, settings, "ui.merge-editor")?; let maybe_editor = match &args { - FullCommandArgs::String(name) => get_tool_config(settings, name)?, - FullCommandArgs::Vec(_) => None, + CommandNameAndArgs::String(name) => get_tool_config(settings, name)?, + CommandNameAndArgs::Vec(_) => None, }; let editor = maybe_editor.unwrap_or_else(|| MergeTool::with_merge_args(&args)); if editor.merge_args.is_empty() { @@ -485,10 +485,10 @@ fn editor_args_from_settings( ui: &mut Ui, settings: &UserSettings, key: &str, -) -> Result { +) -> Result { // TODO: Make this configuration have a table of possible editors and detect the // best one here. - match settings.config().get::(key) { + match settings.config().get::(key) { Ok(args) => Ok(args), Err(config::ConfigError::NotFound(_)) => { let default_editor = "meld"; diff --git a/src/ui.rs b/src/ui.rs index 7ddf1a453..afccc6a95 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -19,12 +19,12 @@ use std::{fmt, io, mem}; use crossterm::tty::IsTty; -use crate::config::FullCommandArgs; +use crate::config::CommandNameAndArgs; use crate::formatter::{Formatter, FormatterFactory, LabeledWriter}; pub struct Ui { color: bool, - pager_cmd: FullCommandArgs, + pager_cmd: CommandNameAndArgs, paginate: PaginationChoice, progress_indicator: bool, formatter_factory: FormatterFactory, @@ -100,7 +100,7 @@ impl Default for PaginationChoice { } } -fn pager_setting(config: &config::Config) -> FullCommandArgs { +fn pager_setting(config: &config::Config) -> CommandNameAndArgs { config .get("ui.pager") .unwrap_or_else(|_| "less -FRX".into()) @@ -320,7 +320,7 @@ impl UiOutput { } } - fn new_paged(pager_cmd: &FullCommandArgs) -> io::Result { + fn new_paged(pager_cmd: &CommandNameAndArgs) -> io::Result { let mut child = pager_cmd.to_command().stdin(Stdio::piped()).spawn()?; let child_stdin = child.stdin.take().unwrap(); Ok(UiOutput::Paged { child, child_stdin })