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
use clap::Parser;
use rustutils_runnable::Runnable;
use std::error::Error;
use std::thread::sleep;
use std::time::Duration;
#[derive(Parser, Clone, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Sleep {
#[clap(parse(try_from_str = parse_duration))]
time: Duration,
}
pub fn parse_duration(value: &str) -> Result<Duration, humantime::DurationError> {
value
.parse()
.map(|seconds: u64| Duration::from_secs(seconds))
.or_else(|_| humantime::parse_duration(value))
}
impl Runnable for Sleep {
fn run(&self) -> Result<(), Box<dyn Error>> {
sleep(self.time);
Ok(())
}
}