Script

Struct Script 

Source
pub struct Script { /* private fields */ }
Expand description

Script represents a single script.

It requires at least to set a scripting language and content. Script’s arguments and options are optional. ScriptingLanguage defines the language in which the script is implemented. Currently, library supports 8 most popular scripting languages, but it is possible to support a custom ones via ScriptingLanguage::Other.

Script stores its content in a file and then executes Cmd provided by Runnable trait implementation.

Implementations§

Source§

impl Script

Source

pub fn new<S>(lang: ScriptingLanguage, content: S) -> Self
where S: Into<String>,

Creates a new script with given scripting language and content.

§Examples
Script::new(ScriptingLanguage::Bash, r#"
    user=$(echo $USER)
    echo "Hello $user"
"#);
Source

pub fn with_args<S, T, I>(lang: ScriptingLanguage, content: S, args: I) -> Self
where S: Into<String>, T: Into<String>, I: IntoIterator<Item = T>,

Creates a new script with given scripting language, content and arguments.

§Examples
Script::with_args(ScriptingLanguage::Bash, "echo $@ | cut -d ' ' -f2", ["arg1", "arg2"]);
Source

pub fn with_options<S>( lang: ScriptingLanguage, content: S, options: CmdOptions, ) -> Self
where S: Into<String>,

Creates a new script with given scripting language, content and options.

§Examples
let content = r#"
    for dir in "$(ls -d */)"; do
       echo "$dir"
    done
"#;
let options = CmdOptions::with_logging(LoggingType::StdoutOnly);
Script::with_options(ScriptingLanguage::Bash, content, options);
Source

pub fn with_args_and_options<S, T, I>( lang: ScriptingLanguage, content: S, args: I, options: CmdOptions, ) -> Self
where S: Into<String>, T: Into<String>, I: IntoIterator<Item = T>,

Creates a new script with given scripting language, content, arguments and options.

§Examples
let content = r#"
    base_dir="$1"
    for dir in "$(ls -d $base_dir/*/)"; do
        echo "$dir"
    done
"#;
let args = vec!["/some/path"];
let options = CmdOptions::with_logging(LoggingType::StdoutOnly);
Script::with_args_and_options(ScriptingLanguage::Bash, content, args, options);
Source

pub fn set_args<S, I>(&mut self, args: I)
where S: Into<String>, I: IntoIterator<Item = S>,

Set a script arguments.

§Examples
let mut script = Script::new(ScriptingLanguage::Bash, "echo $@ | cut -d ' ' -f2");
script.set_args(["arg1", "arg2"]);
Source

pub fn set_options(&mut self, options: CmdOptions)

Set a script options.

§Examples
let mut script = Script::new(ScriptingLanguage::Bash, "echo $@ | cut -d ' ' -f2");
script.set_options(CmdOptions::with_standard_io_messaging());
Source

pub fn add_arg<S>(&mut self, arg: S)
where S: Into<String>,

Add a new argument to the end of argument list. If arguments was not specified during Script creation, it will create new argument list with given argument.

§Examples
let mut script = Script::new(ScriptingLanguage::Bash, "echo $@ | cut -d ' ' -f2");
script.add_arg("arg1");
script.add_arg("arg2");
Source

pub fn language(&self) -> &ScriptingLanguage

Get script language.

Source

pub fn content(&self) -> &str

Get script content.

Source

pub fn args(&self) -> &[String]

Get script arguments.

Source

pub fn options(&self) -> &CmdOptions

Get script options.

Source

pub fn options_mut(&mut self) -> &mut CmdOptions

Update script options via mutable reference.

§Examples
let mut script = Script::new(ScriptingLanguage::Bash, "echo $TEST_ENV_VAR | cut -d ' ' -f2");
script.options_mut().add_env("TEST_ENV_VAR", "example value");

Trait Implementations§

Source§

impl Clone for Script

Source§

fn clone(&self) -> Script

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Script

Source§

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

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

impl<'de> Deserialize<'de> for Script

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Script

Source§

fn eq(&self, other: &Script) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Runnable for Script

Source§

fn bootstrap_cmd(&self, process_dir: &Path) -> Result<Cmd, String>

This method should prepare process to run and return Cmd used to spawn a custom process. If you need to create some files for properly spawning a process, do it inside provided process_dir directory.
Source§

fn clean_after_fail(&self, process_dir: &Path) -> Result<(), String>

This method is called when process spawning fails. Notice that process_dir will be deleted automatically, so there is no need to delete it here.
Source§

impl Serialize for Script

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Script

Source§

impl StructuralPartialEq for Script

Auto Trait Implementations§

§

impl Freeze for Script

§

impl RefUnwindSafe for Script

§

impl Send for Script

§

impl Sync for Script

§

impl Unpin for Script

§

impl UnwindSafe for Script

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,