gix_command

Struct Prepare

source
pub struct Prepare {
    pub command: OsString,
    pub context: Option<Context>,
    pub stdin: Stdio,
    pub stdout: Stdio,
    pub stderr: Stdio,
    pub args: Vec<OsString>,
    pub env: Vec<(OsString, OsString)>,
    pub use_shell: bool,
    pub allow_manual_arg_splitting: bool,
}
Expand description

A structure to keep settings to use when invoking a command via spawn(), after creating it with prepare().

Fields§

§command: OsString

The command to invoke (either with or without shell depending on use_shell.

§context: Option<Context>

Additional information to be passed to the spawned command.

§stdin: Stdio

The way standard input is configured.

§stdout: Stdio

The way standard output is configured.

§stderr: Stdio

The way standard error is configured.

§args: Vec<OsString>

The arguments to pass to the spawned process.

§env: Vec<(OsString, OsString)>

environment variables to set in the spawned process.

§use_shell: bool

If true, we will use sh to execute the command.

§allow_manual_arg_splitting: bool

If true (default true on windows and false everywhere else) we will see if it’s safe to manually invoke command after splitting its arguments as a shell would do. Note that outside of windows, it’s generally not advisable as this removes support for literal shell scripts with shell-builtins.

This mimics the behaviour we see with git on windows, which also won’t invoke the shell there at all.

Only effective if use_shell is true as well, as the shell will be used as a fallback if it’s not possible to split arguments as the command-line contains ‘scripting’.

Implementations§

source§

impl Prepare

Builder

source

pub fn with_shell(self) -> Self

If called, the command will not be executed directly, but with sh, but only if the command passed to prepare requires this.

This also allows to pass shell scripts as command, or use commands that contain arguments which are subsequently parsed by sh.

source

pub fn without_shell(self) -> Self

Unconditionally turn off using the shell when spawning the command. Note that not using the shell is the default so an effective use of this method is some time after with_shell() was called.

source

pub fn with_context(self, ctx: Context) -> Self

Set additional ctx to be used when spawning the process.

Note that this is a must for most kind of commands that git usually spawns, as at least they need to know the correct git repository to function.

source

pub fn with_shell_allow_argument_splitting(self) -> Self

Use a shell, but try to split arguments by hand if this can be safely done without a shell.

If that’s not the case, use a shell instead.

source

pub fn stdin(self, stdio: Stdio) -> Self

Configure the process to use stdio for _stdin.

source

pub fn stdout(self, stdio: Stdio) -> Self

Configure the process to use stdio for stdout.

source

pub fn stderr(self, stdio: Stdio) -> Self

Configure the process to use stdio for _stderr.

source

pub fn arg(self, arg: impl Into<OsString>) -> Self

Add arg to the list of arguments to call the command with.

source

pub fn args(self, args: impl IntoIterator<Item = impl Into<OsString>>) -> Self

Add args to the list of arguments to call the command with.

source

pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self

Add key with value to the environment of the spawned command.

source§

impl Prepare

Finalization

source

pub fn spawn(self) -> Result<Child>

Spawn the command as configured.

Trait Implementations§

source§

impl From<Prepare> for Command

source§

fn from(prep: Prepare) -> Command

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.