1use std::{
2 io::{self, Write},
3 process::{self, Command, Stdio},
4};
5
6pub fn shell(cmd: &str) {
7 println!("{}", cmd);
8 Command::new("sh")
9 .args(&["-c", cmd])
10 .stderr(Stdio::inherit())
11 .stdout(Stdio::inherit())
12 .stdin(Stdio::inherit())
13 .output()
14 .expect("shell_exec failed");
15}
16
17pub fn shell_capture(cmd: &str) -> String {
18 let output = Command::new("sh").args(&["-c", cmd]).output().expect("shell_exec failed");
19 std::str::from_utf8(&output.stdout).expect("shell_exec->from_utf8 failed").to_string()
20}
21
22pub fn user_input(msg: &str) -> String {
23 print!("{}", msg);
24 io::stdout().flush().unwrap();
25 let mut input = String::new();
26 io::stdin().read_line(&mut input).unwrap();
27 input.trim().to_string()
28}
29
30pub fn exit(msg: &str) -> ! {
31 println!("{}", msg);
32 process::exit(1)
33}