Struct reef::Command

source ·
pub struct Command { /* private fields */ }

Implementations§

source§

impl Command

source

pub fn new(name: &str) -> Self

Examples found in repository?
examples/command.rs (line 9)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source

pub fn collect(search: &str, limit: usize) -> Result<Vec<Command>>

Examples found in repository?
examples/command.rs (line 48)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source§

impl Command

source

pub fn name(&self) -> &str

source

pub fn args(&self) -> &Vec<String>

source

pub fn exe_filename(&self) -> &Path

source

pub fn working_directory(&self) -> Option<&Path>

source

pub fn get_timeout(&self) -> Option<&Duration>

source

pub fn stderr(&self) -> &Vec<u8>

source

pub fn timed_out(&self) -> bool

source

pub fn exit_code(&self) -> Option<i32>

source

pub fn start(&self) -> &Option<DateTime<Utc>>

source

pub fn duration(&self) -> Option<Duration>

source

pub fn duration_string(&self) -> String

source

pub fn stdout(&self) -> &Vec<u8>

source

pub fn text(&self) -> Result<String>

source

pub fn status(&self) -> Status

source

pub fn user(&self) -> &str

source

pub fn machine(&self) -> &str

source

pub fn os(&self) -> &str

source

pub fn matches(&self, search: &str) -> bool

source§

impl Command

source

pub fn arg(&mut self, arg: &str) -> &mut Command

Examples found in repository?
examples/command.rs (line 10)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source

pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command

Examples found in repository?
examples/command.rs (line 12)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source

pub fn timeout(&mut self, timeout: Duration) -> &mut Command

Examples found in repository?
examples/command.rs (line 22)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source

pub fn success_log_level(&mut self, level_filter: LevelFilter) -> &mut Command

source

pub fn fail_log_level(&mut self, level_filter: LevelFilter) -> &mut Command

source

pub fn exec(&mut self) -> Result<Command>

Examples found in repository?
examples/command.rs (line 13)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn main() -> Result<()> {
    let c2 = Command::new("git")
        .arg("log")
        .arg("-1")
        .current_dir(&std::env::current_dir().unwrap())
        .exec()?;
    println!("command display: {}", c2);
    println!("\ncommand debug:\n{:#?}", c2);
    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);

    let c3 = Command::new("git")
        .arg("ls-remote")
        .arg("https://gitlab.com/crates-rs/reef.git")
        .arg("HEAD")
        .timeout(Duration::new(0, 0))
        .exec()?;
    println!("{:#?}", c3);

    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
    println!("{:#?}", c4);

    let rake_dir = std::env::temp_dir().join("reef.command.rake");
    if !rake_dir.exists() {
        std::fs::create_dir_all(&rake_dir)?;
    }
    let rakefile = rake_dir.join("rakefile.rb");
    let mut file = File::create(&rakefile)?;
    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
    file.flush()?;
    thread::sleep(Duration::from_millis(500));
    let rake = Command::new("rake")
        .arg("default")
        .current_dir(&rake_dir)
        .timeout(std::time::Duration::from_secs(20 * 60))
        .exec()?;
    println!("{:#?}", rake);
    std::fs::remove_file(&rakefile)?;
    std::fs::remove_dir_all(&rake_dir)?;

    // collect recent history
    let recent = Command::collect("", 3)?;
    println!("recent:\n{:#?}", recent);

    Ok(())
}
source

pub fn set_stdout(&mut self, stdout: Vec<u8>)

source

pub fn set_stderr(&mut self, stderr: Vec<u8>)

Trait Implementations§

source§

impl Clone for Command

source§

fn clone(&self) -> Command

Returns a copy 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 Command

source§

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

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

impl Default for Command

source§

fn default() -> Command

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

impl<'de> Deserialize<'de> for Command

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 Display for Command

source§

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

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

impl Serialize for Command

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,