diff --git a/sfsmcctl/src/main.rs b/sfsmcctl/src/main.rs index ec00137..313c7b2 100644 --- a/sfsmcctl/src/main.rs +++ b/sfsmcctl/src/main.rs @@ -158,12 +158,32 @@ async fn main() -> Result<(), Box> { panic!("Lost connection to D-Bus: {}", err); }); + // Get subcommands (e.g. ("start", None); ("minecraft", Some("stop"))) + let subcommands = clapped.subcommand(); + let subcommands = (subcommands.0, subcommands.1.map(|m| m.subcommand_name()).flatten()); + // Get the action (e.g. subcommand: ("start", None) -> "start"; subcommand: ("minecraft", Some("stop")) -> "stop") + let action = match subcommands { + (a, None) => a, + (_, Some(a)) => a + }; + // The object path + let path = match subcommands.0 { + "minecraft" => "/minecraft", + _ => "/" + }; + // Get a proxy connection to the daemon - let daemon = NativeObject::new(c, "/"); + let object = NativeObject::new(c, path); // TODO: // Perform operations - info!("The daemon is{} running", if !daemon.is_running().await {"n't"} else {""}); + match action { + "start" => object.start().await?, + "stop" => object.stop().await?, + "restart" => object.restart().await?, + "is-running" => info!("Service at path {} is{} running", path, if !object.is_running().await {"n't"} else {""}), + _ => unreachable!("unknown action") + } Ok(()) } \ No newline at end of file