summary history branches tags files
commit:d6011bae475e909e5716af0a17942a3457350807
author:Trevor Bentley
committer:Trevor Bentley
date:Sat Jan 8 17:34:16 2022 +0100
parents:c1fbcb441e15b7b382734bcc689a65868c1381cb
add command-line option to test idle commands and exit
diff --git a/src/main.rs b/src/main.rs
line changes: +12/-0
index 06650a0..c983154
--- a/src/main.rs
+++ b/src/main.rs
@@ -528,6 +528,7 @@ fn exist_audio() -> ExistResult {
 struct CircadianLaunchOptions {
     config_file: String,
     //script_dir: String,
+    test: bool,
 }
 
 #[derive(Default,Debug)]
@@ -599,6 +600,7 @@ fn read_cmdline() -> CircadianLaunchOptions {
         .about(env!("CARGO_PKG_DESCRIPTION"))
         .args_from_usage(
             "-f, --config=[FILE] ''
+             -t, --test 'Run idle tests and exit'
              -d, --script-dir=[DIR] ''")
         .get_matches();
     let config = matches.value_of("config").unwrap_or("/etc/circadian.conf");
@@ -607,6 +609,7 @@ fn read_cmdline() -> CircadianLaunchOptions {
     CircadianLaunchOptions {
         config_file: config.to_owned(),
         //script_dir: script_dir.to_owned(),
+        test: matches.is_present("test"),
     }
 }
 
@@ -802,6 +805,15 @@ fn main() {
         });
     println!("{:?}", config);
 
+    if launch_opts.test {
+        println!("Got --test: running idle test and exiting.");
+        let start = time::now_utc().to_timespec().sec as i64;
+        let idle = test_idle(&config, start);
+        let tests = test_nonidle(&config);
+        println!("Idle Detection Summary:\n{}{}", idle, tests);
+        std::process::exit(0);
+    }
+
     if !config.tty_input && !config.x11_input {
         println!("tty_input or x11_input must be enabled.  Exiting.");
         std::process::exit(1);