Rename mail commands to job commands

This commit is contained in:
cosineblast 2025-03-05 19:45:59 -03:00
parent 04df4130a4
commit d774b1ae96
7 changed files with 29 additions and 67 deletions

View File

@ -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"))]

View File

@ -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<Example> {
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,
}]
}

View File

@ -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<Example> {
vec![Example {
example: "mail recv",
example: "job recv",
description: "Block the current thread while no message arrives",
result: None,
}]

View File

@ -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<Example> {
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,
}]

View File

@ -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)]

View File

@ -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<PipelineData, ShellError> {
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
}
}

View File

@ -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;