From d774b1ae96c11316f1726ff6c10d69629a7e617a Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:45:59 -0300 Subject: [PATCH] Rename mail commands to job commands --- crates/nu-command/src/default_context.rs | 7 ++-- .../{mail_clear.rs => job_clear_mail.rs} | 14 ++++---- .../{mail_recv.rs => job_recv.rs} | 10 +++--- .../{mail_send.rs => job_send.rs} | 12 +++---- .../nu-command/src/experimental/job_spawn.rs | 4 +-- crates/nu-command/src/experimental/mail.rs | 34 ------------------- crates/nu-command/src/experimental/mod.rs | 15 ++++---- 7 files changed, 29 insertions(+), 67 deletions(-) rename crates/nu-command/src/experimental/{mail_clear.rs => job_clear_mail.rs} (80%) rename crates/nu-command/src/experimental/{mail_recv.rs => job_recv.rs} (96%) rename crates/nu-command/src/experimental/{mail_send.rs => job_send.rs} (91%) delete mode 100644 crates/nu-command/src/experimental/mail.rs diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 71b355e9a8..655c8d9437 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -452,11 +452,10 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { JobList, JobKill, JobId, + JobSend, + JobRecv, + JobClearMail, Job, - MailSend, - MailRecv, - MailClear, - Mail, }; #[cfg(all(unix, feature = "os"))] diff --git a/crates/nu-command/src/experimental/mail_clear.rs b/crates/nu-command/src/experimental/job_clear_mail.rs similarity index 80% rename from crates/nu-command/src/experimental/mail_clear.rs rename to crates/nu-command/src/experimental/job_clear_mail.rs index a964901ad7..4fc44944fc 100644 --- a/crates/nu-command/src/experimental/mail_clear.rs +++ b/crates/nu-command/src/experimental/job_clear_mail.rs @@ -1,15 +1,15 @@ use nu_engine::command_prelude::*; #[derive(Clone)] -pub struct MailClear; +pub struct JobClearMail; -impl Command for MailClear { +impl Command for JobClearMail { fn name(&self) -> &str { - "mail clear" + "job clear-mail" } fn description(&self) -> &str { - "Clear mailbox." + "Clear this job's mailbox." } fn extra_description(&self) -> &str { @@ -20,7 +20,7 @@ If a message is received while this command is executing, it may also be discard } fn signature(&self) -> nu_protocol::Signature { - Signature::build("mail clear") + Signature::build("job clear-mail") .category(Category::Experimental) .input_output_types(vec![(Type::Nothing, Type::Nothing)]) .allow_variants_without_examples(true) @@ -50,8 +50,8 @@ If a message is received while this command is executing, it may also be discard fn examples(&self) -> Vec { vec![Example { - example: "let id = job spawn { mail recv | save sent.txt }; 'hi' | mail send $id", - description: "Send a message to a newly spawned job", + example: "job clear-mail", + description: "Clear the mailbox of the current job.", result: None, }] } diff --git a/crates/nu-command/src/experimental/mail_recv.rs b/crates/nu-command/src/experimental/job_recv.rs similarity index 96% rename from crates/nu-command/src/experimental/mail_recv.rs rename to crates/nu-command/src/experimental/job_recv.rs index ca303d3a3a..3a3d120859 100644 --- a/crates/nu-command/src/experimental/mail_recv.rs +++ b/crates/nu-command/src/experimental/job_recv.rs @@ -4,13 +4,13 @@ use nu_engine::command_prelude::*; use nu_protocol::engine::Tag; #[derive(Clone)] -pub struct MailRecv; +pub struct JobRecv; const CTRL_C_CHECK_INTERVAL: Duration = Duration::from_millis(100); -impl Command for MailRecv { +impl Command for JobRecv { fn name(&self) -> &str { - "mail recv" + "job recv" } fn description(&self) -> &str { @@ -34,7 +34,7 @@ in no particular order, regardless of the specified timeout parameter. } fn signature(&self) -> nu_protocol::Signature { - Signature::build("mail recv") + Signature::build("job recv") .category(Category::Experimental) .named("tag", SyntaxShape::Int, "A tag for the message", None) .named( @@ -111,7 +111,7 @@ in no particular order, regardless of the specified timeout parameter. fn examples(&self) -> Vec { vec![Example { - example: "mail recv", + example: "job recv", description: "Block the current thread while no message arrives", result: None, }] diff --git a/crates/nu-command/src/experimental/mail_send.rs b/crates/nu-command/src/experimental/job_send.rs similarity index 91% rename from crates/nu-command/src/experimental/mail_send.rs rename to crates/nu-command/src/experimental/job_send.rs index e750cfb7bc..b063112b27 100644 --- a/crates/nu-command/src/experimental/mail_send.rs +++ b/crates/nu-command/src/experimental/job_send.rs @@ -2,11 +2,11 @@ use nu_engine::command_prelude::*; use nu_protocol::{engine::Tag, JobId}; #[derive(Clone)] -pub struct MailSend; +pub struct JobSend; -impl Command for MailSend { +impl Command for JobSend { fn name(&self) -> &str { - "mail send" + "job send" } fn description(&self) -> &str { @@ -16,7 +16,7 @@ impl Command for MailSend { fn extra_description(&self) -> &str { r#" This command sends a message to a background job, which can then read sent messages -in a first-in-first-out fashion with `mail recv`. When it does so, it may additionally specify a numeric filter tag, +in a first-in-first-out fashion with `job recv`. When it does so, it may additionally specify a numeric filter tag, in which case it will only read messages sent with the exact same filter tag. A message can be any nushell value, and streams are always collected before being sent. @@ -26,7 +26,7 @@ This command never blocks. } fn signature(&self) -> nu_protocol::Signature { - Signature::build("mail send") + Signature::build("job send") .category(Category::Experimental) .required( "id", @@ -105,7 +105,7 @@ This command never blocks. fn examples(&self) -> Vec { vec![Example { - example: "let id = job spawn { mail recv | save sent.txt }; 'hi' | mail send $id", + example: "let id = job spawn { job recv | save sent.txt }; 'hi' | job send $id", description: "Send a message to a newly spawned job", result: None, }] diff --git a/crates/nu-command/src/experimental/job_spawn.rs b/crates/nu-command/src/experimental/job_spawn.rs index 6eff290a29..023f739fca 100644 --- a/crates/nu-command/src/experimental/job_spawn.rs +++ b/crates/nu-command/src/experimental/job_spawn.rs @@ -8,8 +8,8 @@ use std::{ use nu_engine::{command_prelude::*, ClosureEvalOnce}; use nu_protocol::{ - engine::{Closure, CurrentJob, Redirection, Job, Mailbox, ThreadJob}, - report_shell_error, OutDest, Signals, + engine::{Closure, CurrentJob, Job, Mailbox, Redirection, ThreadJob}, + report_shell_error, OutDest, Signals, }; #[derive(Clone)] diff --git a/crates/nu-command/src/experimental/mail.rs b/crates/nu-command/src/experimental/mail.rs deleted file mode 100644 index 63b553ca3b..0000000000 --- a/crates/nu-command/src/experimental/mail.rs +++ /dev/null @@ -1,34 +0,0 @@ -use nu_engine::{command_prelude::*, get_full_help}; - -#[derive(Clone)] -pub struct Mail; - -impl Command for Mail { - fn name(&self) -> &str { - "mail" - } - - fn signature(&self) -> Signature { - Signature::build("mail") - .category(Category::Strings) - .input_output_types(vec![(Type::Nothing, Type::String)]) - } - - fn description(&self) -> &str { - "Various commands for job communication." - } - - fn extra_description(&self) -> &str { - "You must use one of the following subcommands. Using this command as-is will only produce this help message." - } - - fn run( - &self, - engine_state: &EngineState, - stack: &mut Stack, - call: &Call, - _input: PipelineData, - ) -> Result { - Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data()) - } -} diff --git a/crates/nu-command/src/experimental/mod.rs b/crates/nu-command/src/experimental/mod.rs index ec7a55b485..acf2c71e3d 100644 --- a/crates/nu-command/src/experimental/mod.rs +++ b/crates/nu-command/src/experimental/mod.rs @@ -1,15 +1,13 @@ mod is_admin; mod job; +mod job_clear_mail; mod job_id; mod job_kill; mod job_list; +mod job_recv; +mod job_send; mod job_spawn; -mod mail; -mod mail_clear; -mod mail_recv; -mod mail_send; - #[cfg(all(unix, feature = "os"))] mod job_unfreeze; @@ -20,10 +18,9 @@ pub use job_kill::JobKill; pub use job_list::JobList; pub use job_spawn::JobSpawn; -pub use mail::Mail; -pub use mail_clear::MailClear; -pub use mail_recv::MailRecv; -pub use mail_send::MailSend; +pub use job_clear_mail::JobClearMail; +pub use job_recv::JobRecv; +pub use job_send::JobSend; #[cfg(all(unix, feature = "os"))] pub use job_unfreeze::JobUnfreeze;