Struct term_transcript::ExitStatus
source · pub struct ExitStatus(pub i32);
Expand description
Portable, platform-independent version of ExitStatus
from the standard library.
Capturing ExitStatus
Some shells have means to check whether the input command was executed successfully.
For example, in sh
-like shells, one can compare the value of $?
to 0, and
in PowerShell to True
. The exit status can be captured when creating a Transcript
by setting a checker in ShellOptions::with_status_check()
:
Examples
let options = ShellOptions::default();
let mut options = options.with_status_check("echo $?", |captured| {
// Parse captured string to plain text. This transform
// is especially important in transcripts captured from PTY
// since they can contain a *wild* amount of escape sequences.
let captured = captured.to_plaintext().ok()?;
let code: i32 = captured.trim().parse().ok()?;
Some(ExitStatus(code))
});
let transcript = Transcript::from_inputs(&mut options, [
UserInput::command("echo \"Hello world\""),
UserInput::command("some-non-existing-command"),
])?;
let status = transcript.interactions()[0].exit_status();
assert!(status.unwrap().is_success());
// The assertion above is equivalent to:
assert_eq!(status, Some(ExitStatus(0)));
let status = transcript.interactions()[1].exit_status();
assert!(!status.unwrap().is_success());
Tuple Fields§
§0: i32
Implementations§
source§impl ExitStatus
impl ExitStatus
sourcepub fn is_success(self) -> bool
pub fn is_success(self) -> bool
Checks if this is the successful status.
Trait Implementations§
source§impl Clone for ExitStatus
impl Clone for ExitStatus
source§fn clone(&self) -> ExitStatus
fn clone(&self) -> ExitStatus
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ExitStatus
impl Debug for ExitStatus
source§impl Hash for ExitStatus
impl Hash for ExitStatus
source§impl PartialEq<ExitStatus> for ExitStatus
impl PartialEq<ExitStatus> for ExitStatus
source§fn eq(&self, other: &ExitStatus) -> bool
fn eq(&self, other: &ExitStatus) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for ExitStatus
impl Eq for ExitStatus
impl StructuralEq for ExitStatus
impl StructuralPartialEq for ExitStatus
Auto Trait Implementations§
impl RefUnwindSafe for ExitStatus
impl Send for ExitStatus
impl Sync for ExitStatus
impl Unpin for ExitStatus
impl UnwindSafe for ExitStatus
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.