Connect clap with dbus execution
This commit is contained in:
parent
ef655b1aae
commit
36268937de
@ -158,12 +158,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user