From 899d497c9c3f3840f752d2fa52dad9e1f1a85502 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 8 Jul 2020 12:09:37 +0300 Subject: [PATCH] Rename _cmd options to _command for consistency --- meli.1 | 4 ++-- meli.conf.5 | 8 +++---- samples/sample-config.toml | 4 ++-- src/components/mail/compose.rs | 41 ++++++++++++++++++---------------- src/conf/composing.rs | 17 +++++++++----- src/conf/overrides.rs | 11 ++++----- 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/meli.1 b/meli.1 index f20a55fca..ede7a5ae0 100644 --- a/meli.1 +++ b/meli.1 @@ -213,7 +213,7 @@ At any time you may press to launch your editor (see .Xr meli.conf 5 COMPOSING Ns , setting -.Ic editor_cmd +.Ic editor_command for how to select which editor to launch). Attachments may be handled with the .Em add-attachment Ns @@ -225,7 +225,7 @@ Finally, pressing will send your message by piping it into a binary of your choosing (see .Xr meli.conf 5 COMPOSING Ns , setting -.Ic mailer_cmd Ns +.Ic mailer_command Ns ). To save your draft without sending it, issue command .Cm close diff --git a/meli.conf.5 b/meli.conf.5 index 9ef22dd2b..54550c1ce 100644 --- a/meli.conf.5 +++ b/meli.conf.5 @@ -106,8 +106,8 @@ script = "notify-send" [composing] # required for sending e-mail -mailer_cmd = 'msmtp --read-recipients --read-envelope-from' -editor_cmd = 'vim +/^$' +mailer_command = 'msmtp --read-recipients --read-envelope-from' +editor_command = 'vim +/^$' [shortcuts] [shortcuts.composing] @@ -323,9 +323,9 @@ Example: .El .Sh COMPOSING .Bl -tag -width 36n -.It Ic mailer_cmd Ar String +.It Ic mailer_command Ar String command to pipe new mail to, exit code must be 0 for success. -.It Ic editor_cmd Ar String +.It Ic editor_command Ar String command to launch editor. Can have arguments. Draft filename is given as the last argument. diff --git a/samples/sample-config.toml b/samples/sample-config.toml index 83bacfe98..808640f7d 100644 --- a/samples/sample-config.toml +++ b/samples/sample-config.toml @@ -105,8 +105,8 @@ #[composing] # required for sending e-mail -#mailer_cmd = 'msmtp --read-recipients --read-envelope-from' -#editor_cmd = 'vim +/^$' # optional, by default $EDITOR is used. +#mailer_command = 'msmtp --read-recipients --read-envelope-from' +#editor_command = 'vim +/^$' # optional, by default $EDITOR is used. # # #[pgp] diff --git a/src/components/mail/compose.rs b/src/components/mail/compose.rs index b771ebf07..63cfd2117 100644 --- a/src/components/mail/compose.rs +++ b/src/components/mail/compose.rs @@ -947,17 +947,17 @@ impl Component for Composer { && shortcut!(key == shortcuts[Self::DESCRIPTION]["edit_mail"]) => { /* Edit draft in $EDITOR */ - let editor = if let Some(editor_cmd) = - mailbox_acc_settings!(context[self.account_cursor].composing.editor_cmd) + let editor = if let Some(editor_command) = + mailbox_acc_settings!(context[self.account_cursor].composing.editor_command) .as_ref() { - editor_cmd.to_string() + editor_command.to_string() } else { match std::env::var("EDITOR") { Err(e) => { context.replies.push_back(UIEvent::Notification( Some(e.to_string()), - "$EDITOR is not set. You can change an envvar's value with setenv or set composing.editor_cmd setting in your configuration.".to_string(), + "$EDITOR is not set. You can change an envvar's value with setenv or set composing.editor_command setting in your configuration.".to_string(), Some(NotificationType::ERROR), )); return true; @@ -1000,13 +1000,16 @@ impl Component for Composer { context.input_kill(); } - let editor_cmd = format!("{} {}", editor, f.path().display()); + let editor_command = format!("{} {}", editor, f.path().display()); log( - format!("Executing: sh -c \"{}\"", editor_cmd.replace("\"", "\\\"")), + format!( + "Executing: sh -c \"{}\"", + editor_command.replace("\"", "\\\"") + ), DEBUG, ); match Command::new("sh") - .args(&["-c", &editor_cmd]) + .args(&["-c", &editor_command]) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .spawn() @@ -1051,18 +1054,18 @@ impl Component for Composer { } UIEvent::Action(ref a) => { match a { - Action::Compose(ComposeAction::AddAttachmentPipe(ref cmd)) => { - if cmd.is_empty() { + Action::Compose(ComposeAction::AddAttachmentPipe(ref command)) => { + if command.is_empty() { context.replies.push_back(UIEvent::Notification( None, - format!("pipe cmd value is invalid: {}", cmd), + format!("pipe command value is invalid: {}", command), Some(NotificationType::ERROR), )); return false; } let f = create_temp_file(&[], None, None, true); match std::process::Command::new("sh") - .args(&["-c", cmd]) + .args(&["-c", command]) .stdin(std::process::Stdio::null()) .stdout(std::process::Stdio::from(f.file())) .spawn() @@ -1070,7 +1073,7 @@ impl Component for Composer { Ok(child) => { let _ = child .wait_with_output() - .expect("failed to launch cmd") + .expect("failed to launch command") .stdout; let mut attachment = match melib::email::attachment_from_file(f.path()) { @@ -1100,7 +1103,7 @@ impl Component for Composer { Err(err) => { context.replies.push_back(UIEvent::Notification( None, - format!("could not execute pipe cmd {}: {}", cmd, err), + format!("could not execute pipe command {}: {}", command, err), Some(NotificationType::ERROR), )); return true; @@ -1280,18 +1283,18 @@ pub fn send_draft( use std::io::Write; use std::process::{Command, Stdio}; let format_flowed = *mailbox_acc_settings!(context[account_cursor].composing.format_flowed); - let cmd = mailbox_acc_settings!(context[account_cursor].composing.mailer_cmd); - if cmd.is_empty() { + let command = mailbox_acc_settings!(context[account_cursor].composing.mailer_command); + if command.is_empty() { context.replies.push_back(UIEvent::Notification( None, - String::from("mailer_cmd configuration value is empty"), + String::from("mailer_command configuration value is empty"), Some(NotificationType::ERROR), )); return false; } let bytes; let mut msmtp = Command::new("sh") - .args(&["-c", cmd]) + .args(&["-c", command]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() @@ -1395,12 +1398,12 @@ pub fn send_draft( let error_message = if let Some(exit_code) = output.code() { format!( "Could not send e-mail using `{}`: Process exited with {}", - cmd, exit_code + command, exit_code ) } else { format!( "Could not send e-mail using `{}`: Process was killed by signal", - cmd + command ) }; context.replies.push_back(UIEvent::Notification( diff --git a/src/conf/composing.rs b/src/conf/composing.rs index 9dfa3d9bf..791015447 100644 --- a/src/conf/composing.rs +++ b/src/conf/composing.rs @@ -28,11 +28,16 @@ use std::collections::HashMap; pub struct ComposingSettings { /// A command to pipe new emails to /// Required - #[serde(alias = "mailer-cmd")] - pub mailer_cmd: String, + #[serde(alias = "mailer-command", alias = "mailer-cmd", alias = "mailer_cmd")] + pub mailer_command: String, /// Command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up. - #[serde(default = "none", alias = "editor-cmd")] - pub editor_cmd: Option, + #[serde( + default = "none", + alias = "editor-command", + alias = "editor-cmd", + alias = "editor_cmd" + )] + pub editor_command: Option, /// Embed editor (for terminal interfaces) instead of forking and waiting. #[serde(default = "false_val")] pub embed: bool, @@ -49,8 +54,8 @@ pub struct ComposingSettings { impl Default for ComposingSettings { fn default() -> Self { ComposingSettings { - mailer_cmd: String::new(), - editor_cmd: None, + mailer_command: String::new(), + editor_command: None, embed: false, format_flowed: true, default_header_values: HashMap::default(), diff --git a/src/conf/overrides.rs b/src/conf/overrides.rs index 733897ccf..aeb00c5b3 100644 --- a/src/conf/overrides.rs +++ b/src/conf/overrides.rs @@ -202,12 +202,13 @@ impl Default for ShortcutsOverride { pub struct ComposingSettingsOverride { #[doc = " A command to pipe new emails to"] #[doc = " Required"] + #[serde(alias = "mailer-command", alias = "mailer-cmd", alias = "mailer_cmd")] #[serde(default)] - pub mailer_cmd: Option, + pub mailer_command: Option, #[doc = " Command to launch editor. Can have arguments. Draft filename is given as the last argument. If it's missing, the environment variable $EDITOR is looked up."] - #[serde(alias = "editor-cmd")] + #[serde(alias = "editor-command", alias = "editor-cmd", alias = "editor_cmd")] #[serde(default)] - pub editor_cmd: Option>, + pub editor_command: Option>, #[doc = " Embed editor (for terminal interfaces) instead of forking and waiting."] #[serde(default)] pub embed: Option, @@ -225,8 +226,8 @@ pub struct ComposingSettingsOverride { impl Default for ComposingSettingsOverride { fn default() -> Self { ComposingSettingsOverride { - mailer_cmd: None, - editor_cmd: None, + mailer_command: None, + editor_command: None, embed: None, format_flowed: None, default_header_values: None,