1use anyhow::Result;
2use reef::Command;
3use std::fs::File;
4use std::io::Write;
5use std::thread;
6use std::time::Duration;
7
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 let recent = Command::collect("", 3)?;
49 println!("recent:\n{:#?}", recent);
50
51 Ok(())
52}