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::Parser;
use clap_complete::Shell; use clap_complete::Shell;
#[derive(Parser, Debug)] #[derive(Debug, Parser, Clone)]
#[clap(name = "discordrpc")] #[clap(name = "discordrpc")]
pub struct Cli { pub struct Cli {
#[clap( #[clap(
@ -120,11 +120,21 @@ pub struct Cli {
)] )]
pub enable_time: bool, 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( #[clap(
long = "print-completions", long = "print-completions",
value_name = "shell", value_name = "shell",
arg_enum, arg_enum,
display_order = 13 display_order = 14
)] )]
pub print_completions: Option<Shell>, pub print_completions: Option<Shell>,
} }

View File

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