add `--timeout` arg

This commit is contained in:
MedzikUser 2022-03-09 18:23:26 +01:00
parent fd56ade4ed
commit f55a67b626
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
2 changed files with 24 additions and 6 deletions

View File

@ -1,7 +1,7 @@
use clap::Parser;
use clap_complete::Shell;
#[derive(Parser, Debug)]
#[derive(Debug, Parser, Clone)]
#[clap(name = "discordrpc")]
pub struct Cli {
#[clap(
@ -120,11 +120,21 @@ pub struct Cli {
)]
pub enable_time: bool,
#[clap(
short = 'E',
long = "timeout",
help = "Exit after X seconds",
default_value="0",
required = false,
display_order = 13
)]
pub timeout: u64,
#[clap(
long = "print-completions",
value_name = "shell",
arg_enum,
display_order = 13
display_order = 14
)]
pub print_completions: Option<Shell>,
}

View File

@ -29,7 +29,7 @@ fn main() {
}
// * start discord rpc
execute::run(args);
execute::run(args.clone());
println!(
"{} {}",
@ -37,8 +37,16 @@ fn main() {
"Press Ctrl+C to exit!".magenta()
);
loop {
// * empty `loop {}` wastes CPU cycles
sleep(Duration::new(9999999, 9999999));
if args.timeout != 0 {
sleep(Duration::from_secs(args.timeout));
println!("{}", "Stopping due to timeout...".blue());
exit(0)
} else {
loop {
// * empty `loop {}` wastes CPU cycles
sleep(Duration::from_secs(9999999));
}
}
}