Struct 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)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
Source

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

Examples found in repository?
examples/command.rs (line 48)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
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)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
Source

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

Examples found in repository?
examples/command.rs (line 12)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
Source

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

Examples found in repository?
examples/command.rs (line 22)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
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)
8fn main() -> Result<()> {
9    let c2 = Command::new("git")
10        .arg("log")
11        .arg("-1")
12        .current_dir(&std::env::current_dir().unwrap())
13        .exec()?;
14    println!("command display: {}", c2);
15    println!("\ncommand debug:\n{:#?}", c2);
16    println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
17
18    let c3 = Command::new("git")
19        .arg("ls-remote")
20        .arg("https://gitlab.com/crates-rs/reef.git")
21        .arg("HEAD")
22        .timeout(Duration::new(0, 0))
23        .exec()?;
24    println!("{:#?}", c3);
25
26    let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
27    println!("{:#?}", c4);
28
29    let rake_dir = std::env::temp_dir().join("reef.command.rake");
30    if !rake_dir.exists() {
31        std::fs::create_dir_all(&rake_dir)?;
32    }
33    let rakefile = rake_dir.join("rakefile.rb");
34    let mut file = File::create(&rakefile)?;
35    file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
36    file.flush()?;
37    thread::sleep(Duration::from_millis(500));
38    let rake = Command::new("rake")
39        .arg("default")
40        .current_dir(&rake_dir)
41        .timeout(std::time::Duration::from_secs(20 * 60))
42        .exec()?;
43    println!("{:#?}", rake);
44    std::fs::remove_file(&rakefile)?;
45    std::fs::remove_dir_all(&rake_dir)?;
46
47    // collect recent history
48    let recent = Command::collect("", 3)?;
49    println!("recent:\n{:#?}", recent);
50
51    Ok(())
52}
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 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,