managecraft 0.1.0

A CLI Utility to communicate with your Minecraft server over the RCON protocol.
Documentation
use clap::Clap;
use std::fmt::{Display, Formatter, Result};
use std::option::Option;

/// Parse in command line arguments
pub fn parse_opts() -> Opts {
    Opts::parse()
}

/// Structure to define all command line behaviour
/// and `--help` output
#[derive(Clap)]
pub struct Opts {
    #[clap(subcommand)]
    pub subcmd: SubCommand,
}

/// Collection of subcommands that can be provided
/// on the command line
#[derive(Clap)]
pub enum SubCommand {
    Execute(Execute),
    Say(Say),
    SaveAll(SaveAll),
}

/// Execute an arbitrary command
#[derive(Clap)]
pub struct Execute {
    /// Arbitrary command
    pub command: String,
}

/// Broadcast a message to the server
#[derive(Clap)]
pub struct Say {
    /// Message content
    pub message: String,
}

/// Save the server world state
#[derive(Clap)]
pub struct SaveAll {
    /// Force all the chunks to be saved to disk
    /// immediately, freezing the server for a
    /// short time.
    #[clap(short, long)]
    pub flush: bool,
}

impl Display for Execute {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "Executing: '{}'", self.command)
    }
}

impl Display for Say {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "Saying: '{}'", self.message)
    }
}

impl Display for SaveAll {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "Saving: (flush: {})", self.flush)
    }
}