add `--timeout` arg
This commit is contained in:
parent
fd56ade4ed
commit
f55a67b626
|
@ -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>,
|
||||
}
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue