From 2591050fbed3ba9d79e8d8aac8b1b287ed0106b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Thu, 10 Jun 2021 01:43:40 +0300 Subject: [PATCH] Clarify `exec` help message; Update to engine-p (#3588) * Fix and clarify description of 'exec' Most importantly, I added the information that it replaces the current process. * Convert exec to OutputStream; Remove unused trait * Remove dead code & unused imports on non-unix --- crates/nu-command/src/commands/exec.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/commands/exec.rs b/crates/nu-command/src/commands/exec.rs index 20ed4f490a..e2de15baab 100644 --- a/crates/nu-command/src/commands/exec.rs +++ b/crates/nu-command/src/commands/exec.rs @@ -2,12 +2,15 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::{Signature, SyntaxShape}; + +#[cfg(unix)] use nu_source::Tagged; +#[cfg(unix)] use std::path::PathBuf; pub struct Exec; -#[derive(Deserialize)] +#[cfg(unix)] pub struct ExecArgs { pub command: Tagged, pub rest: Vec>, @@ -23,22 +26,26 @@ impl WholeStreamCommand for Exec { .required("command", SyntaxShape::FilePath, "the command to execute") .rest( SyntaxShape::GlobPattern, - "any additional arguments for command", + "any additional arguments for the command", ) } fn usage(&self) -> &str { - "Execute command." + "Execute a command, replacing the current process." } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn extra_usage(&self) -> &str { + "Currently supported only on Unix-based systems." + } + + fn run(&self, args: CommandArgs) -> Result { exec(args) } fn examples(&self) -> Vec { vec![ Example { - description: "Execute 'ps aux'", + description: "Execute external 'ps aux' tool", example: "exec ps aux", result: None, }, @@ -52,7 +59,7 @@ impl WholeStreamCommand for Exec { } #[cfg(unix)] -fn exec(args: CommandArgs) -> Result { +fn exec(args: CommandArgs) -> Result { use std::os::unix::process::CommandExt; use std::process::Command; @@ -79,7 +86,7 @@ fn exec(args: CommandArgs) -> Result { } #[cfg(not(unix))] -fn exec(args: CommandArgs) -> Result { +fn exec(args: CommandArgs) -> Result { Err(ShellError::labeled_error( "Error on exec", "exec is not supported on your platform",