avoid confusion with std command

pull/526/head
Lucas Nogueira 2 years ago
parent 0ae5de8e42
commit b4493a24ad
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

@ -0,0 +1,5 @@
---
"shell": "patch"
---
Added `Command::arg`, `Command::env` and changed `Command::new` input type.

@ -1,5 +0,0 @@
---
"shell": "patch"
---
Refactor the `Command` API adhere to `std::process::Command`.

1035
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -133,12 +133,12 @@ pub fn execute<R: Runtime>(
}
};
if let Some(cwd) = options.cwd {
command.current_dir(cwd);
command = command.current_dir(cwd);
}
if let Some(env) = options.env {
command.envs(env);
command = command.envs(env);
} else {
command.env_clear();
command = command.env_clear();
}
let encoding = match options.encoding {
Option::None => EncodingWrapper::Text(None),

@ -5,7 +5,6 @@
use std::{
ffi::OsStr,
io::{BufReader, Write},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
process::{Command as StdCommand, Stdio},
sync::{Arc, RwLock},
@ -56,20 +55,6 @@ pub enum CommandEvent {
#[derive(Debug)]
pub struct Command(StdCommand);
impl Deref for Command {
type Target = StdCommand;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for Command {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// Spawned child process.
#[derive(Debug)]
pub struct CommandChild {
@ -158,6 +143,61 @@ impl Command {
Ok(Self::new(relative_command_path(program.as_ref())?))
}
/// Appends an argument to the command.
#[must_use]
pub fn arg<S: AsRef<OsStr>>(mut self, arg: S) -> Self {
self.0.arg(arg);
self
}
/// Appends arguments to the command.
#[must_use]
pub fn args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
self.0.args(args);
self
}
/// Clears the entire environment map for the child process.
#[must_use]
pub fn env_clear(mut self) -> Self {
self.0.env_clear();
self
}
/// Inserts or updates an explicit environment variable mapping.
#[must_use]
pub fn env<K, V>(mut self, key: K, value: V) -> Self
where
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.0.env(key, value);
self
}
/// Adds or updates multiple environment variable mappings.
#[must_use]
pub fn envs<I, K, V>(mut self, envs: I) -> Self
where
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
V: AsRef<OsStr>,
{
self.0.envs(envs);
self
}
/// Sets the working directory for the child process.
#[must_use]
pub fn current_dir<P: AsRef<Path>>(mut self, current_dir: P) -> Self {
self.0.current_dir(current_dir);
self
}
/// Spawns the command.
///
/// # Examples

@ -237,15 +237,13 @@ impl Scope {
.into_owned()
})
.unwrap_or_else(|| command.command.to_string_lossy().into_owned());
let mut command = if command.sidecar {
let command = if command.sidecar {
Command::new_sidecar(command_s).map_err(|e| Error::Sidecar(e.to_string()))?
} else {
Command::new(command_s)
};
command.args(args);
Ok(command)
Ok(command.args(args))
}
/// Open a path in the default (or specified) browser.

Loading…
Cancel
Save