forked from containerd/runwasi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rs
37 lines (34 loc) · 1.12 KB
/
main.rs
1
2
3
4
5
6
7
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
use std::fs::File;
use std::io::prelude::*;
use std::thread::sleep;
use std::time::Duration;
use std::{env, process};
fn main() {
let args: Vec<_> = env::args().collect();
let mut cmd = "daemon";
if args.len() >= 2 {
cmd = &args[1];
}
match cmd {
"echo" => println!("{}", &args[2..].join(" ")),
"sleep" => sleep(Duration::from_secs_f64(args[2].parse::<f64>().unwrap())),
"exit" => process::exit(args[2].parse::<i32>().unwrap()),
"write" => {
let mut file = File::create(&args[2]).unwrap();
file.write_all(args[3..].join(" ").as_bytes()).unwrap();
}
"daemon" => loop {
println!(
"This is a song that never ends.\nYes, it goes on and on my friends.\nSome people \
started singing it not knowing what it was,\nSo they'll continue singing it \
forever just because...\n"
);
sleep(Duration::from_secs(1));
},
_ => {
eprintln!("unknown command: {0}", args[1]);
process::exit(1);
}
}
eprintln!("exiting");
}