Skip to main content

ShellJs

Struct ShellJs 

Source
pub struct ShellJs {
    pub config: Config,
    pub env: HashMap<String, String>,
    /* private fields */
}
Expand description

A portable Rust counterpart of the ShellJS command-call interface. Arguments are individual values; command calls never concatenate them as shell syntax. Unlike JavaScript ShellJS, cwd changes affect this session only.

Fields§

§config: Config

Session configuration.

§env: HashMap<String, String>

Environment used by commands.

Implementations§

Source§

impl ShellJs

Source

pub fn new() -> Self

Create a session rooted in the current directory.

Source

pub fn cwd(&self) -> &Path

Current session directory.

Source

pub fn error(&self) -> Option<&str>

Error text from the last command, or None after success.

Source

pub fn error_code(&self) -> i32

Exit code of the last command.

Source

pub async fn call( &mut self, command: &str, args: &[&str], ) -> Result<CommandResult>

Run a supported ShellJS command. Unsupported command names return 127; external programs use cmd (argv) or exec (explicit shell syntax).

Source

pub async fn cat(&mut self, args: &[&str]) -> Result<CommandResult>

Run cat with separate argument values.

Source

pub async fn chmod(&mut self, args: &[&str]) -> Result<CommandResult>

Run chmod with separate argument values.

Source

pub async fn cp(&mut self, args: &[&str]) -> Result<CommandResult>

Run cp with separate argument values.

Source

pub async fn echo(&mut self, args: &[&str]) -> Result<CommandResult>

Run echo with separate argument values.

Source

pub async fn find(&mut self, args: &[&str]) -> Result<CommandResult>

Run find with separate argument values.

Source

pub async fn grep(&mut self, args: &[&str]) -> Result<CommandResult>

Run grep with separate argument values.

Source

pub async fn head(&mut self, args: &[&str]) -> Result<CommandResult>

Run head with separate argument values.

Source

pub async fn ln(&mut self, args: &[&str]) -> Result<CommandResult>

Run ln with separate argument values.

Source

pub async fn ls(&mut self, args: &[&str]) -> Result<CommandResult>

Run ls with separate argument values.

Source

pub async fn mkdir(&mut self, args: &[&str]) -> Result<CommandResult>

Run mkdir with separate argument values.

Source

pub async fn mv(&mut self, args: &[&str]) -> Result<CommandResult>

Run mv with separate argument values.

Source

pub async fn pwd(&mut self, args: &[&str]) -> Result<CommandResult>

Run pwd with separate argument values.

Source

pub async fn rm(&mut self, args: &[&str]) -> Result<CommandResult>

Run rm with separate argument values.

Source

pub async fn sed(&mut self, args: &[&str]) -> Result<CommandResult>

Run sed with separate argument values.

Source

pub async fn sort(&mut self, args: &[&str]) -> Result<CommandResult>

Run sort with separate argument values.

Source

pub async fn tail(&mut self, args: &[&str]) -> Result<CommandResult>

Run tail with separate argument values.

Source

pub async fn touch(&mut self, args: &[&str]) -> Result<CommandResult>

Run touch with separate argument values.

Source

pub async fn uniq(&mut self, args: &[&str]) -> Result<CommandResult>

Run uniq with separate argument values.

Source

pub async fn which(&mut self, args: &[&str]) -> Result<CommandResult>

Run which with separate argument values.

Source

pub async fn basename(&mut self, args: &[&str]) -> Result<CommandResult>

Run basename with separate argument values.

Source

pub async fn dirname(&mut self, args: &[&str]) -> Result<CommandResult>

Run dirname with separate argument values.

Source

pub async fn sleep(&mut self, args: &[&str]) -> Result<CommandResult>

Run sleep with separate argument values.

Source

pub async fn env(&mut self, args: &[&str]) -> Result<CommandResult>

Run env with separate argument values.

Source

pub async fn seq(&mut self, args: &[&str]) -> Result<CommandResult>

Run seq with separate argument values.

Source

pub async fn tee(&mut self, args: &[&str]) -> Result<CommandResult>

Run tee with separate argument values.

Source

pub async fn cd(&mut self, args: &[&str]) -> Result<CommandResult>

Change this session’s directory without changing the host process cwd.

Source

pub async fn test(&mut self, args: &[&str]) -> Result<bool>

Evaluate a file test, returning a boolean.

Source

pub async fn cmd( &mut self, program: &str, args: &[&str], ) -> Result<CommandResult>

Execute a program with exact arguments, bypassing the shell.

Source

pub async fn exec(&mut self, command: &str) -> Result<CommandResult>

Execute an explicitly supplied shell command.

Source

pub fn dirs(&self) -> CommandResult

List the current directory followed by the saved directory stack.

Source

pub async fn pushd(&mut self, args: &[&str]) -> Result<CommandResult>

Save the current directory and change to the provided directory.

Source

pub async fn popd(&mut self) -> Result<CommandResult>

Restore the most recently saved directory.

Source

pub fn tempdir(&self) -> PathBuf

Return the platform temporary directory.

Source

pub fn set(&mut self, option: &str) -> Result<CommandResult>

Set fatal (-e/+e), verbose (-v/+v) or glob (-f/+f) modes.

Source

pub async fn to( &mut self, result: &CommandResult, path: &str, append: bool, ) -> Result<CommandResult>

Write captured stdout to a file (append=true corresponds to toEnd).

Source

pub fn command(&self, name: &str, args: &[&str]) -> String

Build a safely quoted native command for explicit mixed pipelines.

Trait Implementations§

Source§

impl Debug for ShellJs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShellJs

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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.
Source§

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.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.