Struct term_transcript::ShellOptions
source · [−]pub struct ShellOptions<Cmd = Command> { /* private fields */ }
Expand description
Options for executing commands in the shell. Used in Transcript::from_inputs()
and in TestConfig
.
The type param maps to extensions available for the shell. For example, StdShell
extension allows to specify custom aliases for the executed commands.
Implementations
sourceimpl ShellOptions<StdShell>
impl ShellOptions<StdShell>
sourcepub fn powershell() -> Self
pub fn powershell() -> Self
Creates options for PowerShell.
sourcepub fn with_alias(self, name: &str, path_to_bin: &str) -> Self
pub fn with_alias(self, name: &str, path_to_bin: &str) -> Self
Creates an alias for the binary at path_to_bin
, which should be an absolute path.
This allows to call the binary using this alias without complex preparations (such as
installing it globally via cargo install
), and is more flexible than
Self::with_cargo_path()
.
In integration tests, you may use env!("CARGO_BIN_EXE_<name>")
to get a path
to binary targets.
Limitations
- For Bash and PowerShell,
name
must be a valid name of a function. Forsh
,name
must be a valid name for thealias
command. Thename
validity is not checked.
sourceimpl<Cmd: ConfigureCommand> ShellOptions<Cmd>
impl<Cmd: ConfigureCommand> ShellOptions<Cmd>
sourcepub fn with_current_dir(self, current_dir: impl AsRef<Path>) -> Self
pub fn with_current_dir(self, current_dir: impl AsRef<Path>) -> Self
Changes the current directory of the command.
sourcepub fn with_io_timeout(self, io_timeout: Duration) -> Self
pub fn with_io_timeout(self, io_timeout: Duration) -> Self
Sets the I/O timeout for shell commands. This determines how long methods like
Transcript::from_inputs()
wait
for output of a command before proceeding to the next command. Longer values
allow to capture output more accurately, but result in longer execution.
By default, the I/O timeout is 1 second.
sourcepub fn with_init_timeout(self, init_timeout: Duration) -> Self
pub fn with_init_timeout(self, init_timeout: Duration) -> Self
Sets an additional initialization timeout (relative to the one set by
Self::with_io_timeout()
) before reading the output of the first command.
By default, the initialization timeout is zero.
sourcepub fn with_init_command(self, command: impl Into<String>) -> Self
pub fn with_init_command(self, command: impl Into<String>) -> Self
Adds an initialization command. Such commands are sent to the shell before executing any user input. The corresponding output from the shell is not captured.
sourcepub fn with_env(self, name: impl AsRef<str>, value: impl AsRef<OsStr>) -> Self
pub fn with_env(self, name: impl AsRef<str>, value: impl AsRef<OsStr>) -> Self
Sets the value
of an environment variable with the specified name
.
sourcepub fn with_line_mapper<F>(self, mapper: F) -> Self where
F: FnMut(String) -> Option<String> + 'static,
pub fn with_line_mapper<F>(self, mapper: F) -> Self where
F: FnMut(String) -> Option<String> + 'static,
Sets the line mapper for the shell. This allows to filter and/or map terminal outputs.
sourcepub fn with_cargo_path(self) -> Self
pub fn with_cargo_path(self) -> Self
Adds paths to cargo binaries (including examples) to the PATH
env variable
for the shell described by these options.
This allows to call them by the corresponding filename, without specifying a path
or doing complex preparations (e.g., calling cargo install
).
Limitations
- The caller must be a unit or integration test; the method will work improperly otherwise.
sourcepub fn with_additional_path(self, path: impl Into<PathBuf>) -> Self
pub fn with_additional_path(self, path: impl Into<PathBuf>) -> Self
Adds a specified path to the PATH
env variable for the shell described by these options.
This method can be called multiple times to add multiple paths and is composable
with Self::with_cargo_path()
.
Trait Implementations
sourceimpl<Cmd: Debug> Debug for ShellOptions<Cmd>
impl<Cmd: Debug> Debug for ShellOptions<Cmd>
sourceimpl Default for ShellOptions
impl Default for ShellOptions
Auto Trait Implementations
impl<Cmd = Command> !RefUnwindSafe for ShellOptions<Cmd>
impl<Cmd = Command> !Send for ShellOptions<Cmd>
impl<Cmd = Command> !Sync for ShellOptions<Cmd>
impl<Cmd> Unpin for ShellOptions<Cmd> where
Cmd: Unpin,
impl<Cmd = Command> !UnwindSafe for ShellOptions<Cmd>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more