Add basic clap functionality

This commit is contained in:
Elias Schriefer 2020-09-21 00:59:50 +02:00
parent cc4d0f08a4
commit ef655b1aae
2 changed files with 39 additions and 1 deletions

View File

@ -7,7 +7,7 @@ authors = ["Elias Schriefer"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "2.33", features = ["wrap_help", "color"] }
toml = "0.5" toml = "0.5"
tokio = { version = "0.2", features = ["full"] } tokio = { version = "0.2", features = ["full"] }
async-minecraft-ping = "0.2" async-minecraft-ping = "0.2"

View File

@ -4,6 +4,7 @@ use dbus::{
Error Error
}; };
use std::sync::Arc; use std::sync::Arc;
use clap::clap_app;
const DBUS_NAME: &'static str = "org.ddnss.sfs.mc"; const DBUS_NAME: &'static str = "org.ddnss.sfs.mc";
@ -109,6 +110,43 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init(); env_logger::init();
// TODO: use clap // TODO: use clap
let clapped = clap_app!((clap::crate_name!()) =>
(version: clap::crate_version!())
(author: &*clap::crate_authors!().split(":").collect::<Vec<_>>().join(", "))
(about: clap::crate_description!())
(@setting DeriveDisplayOrder)
(@setting SubcommandRequiredElseHelp)
(@setting GlobalVersion)
(@subcommand start =>
(about: "Start sfsmcd")
)
(@subcommand stop =>
(about: "Stop sfsmcd")
)
(@subcommand restart =>
(about: "Restart sfsmcd")
)
(subcommand: clap::SubCommand::with_name("is-running")
.about("Get whether sfsmcd is running")
)
(@subcommand minecraft =>
(about: "The minecraft server service")
(@setting DeriveDisplayOrder)
(@setting SubcommandRequiredElseHelp)
(@subcommand start =>
(about: "Start minecraft server")
)
(@subcommand stop =>
(about: "Stop minecraft server")
)
(@subcommand restart =>
(about: "Restart minecraft server")
)
(subcommand: clap::SubCommand::with_name("is-running")
.about("Get whether minecraft server is running")
)
)
).get_matches();
// Connect with D-Bus // Connect with D-Bus
let (resource, c) = dbus_tokio::connection::new_system_sync()?; let (resource, c) = dbus_tokio::connection::new_system_sync()?;