summaryrefslogtreecommitdiffstats
path: root/src/device.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/device.rs b/src/device.rs
new file mode 100644
index 0000000..3911b25
--- /dev/null
+++ b/src/device.rs
@@ -0,0 +1,27 @@
+use std::{env::ArgsOs, process};
+
+use crate::config::Config;
+
+mod on_action;
+mod set_state;
+
+pub fn main(argv0: &str, config: Config, mut args: ArgsOs) {
+ let (Some(device_name), Some(command)) = (args.next(), args.next()) else {
+ eprintln!("Usage: {argv0} device <device-name> <command> [args...]");
+ process::exit(1);
+ };
+
+ let Some(device_name) = device_name.to_str() else {
+ eprintln!("{argv0}: error: Invalid device name");
+ process::exit(1);
+ };
+
+ match command.to_str() {
+ Some("on-action") => on_action::main(argv0, config, device_name, args),
+ Some("set-state") => set_state::main(argv0, config, device_name, args),
+ _ => {
+ eprintln!("{argv0}: error: Unknown device command: {command:?}");
+ process::exit(1);
+ }
+ }
+}