use clap::Clap;
use std::fmt::{Display, Formatter, Result};
use std::option::Option;
pub fn parse_opts() -> Opts {
Opts::parse()
}
#[derive(Clap)]
pub struct Opts {
#[clap(subcommand)]
pub subcmd: SubCommand,
}
#[derive(Clap)]
pub enum SubCommand {
Execute(Execute),
Say(Say),
SaveAll(SaveAll),
}
#[derive(Clap)]
pub struct Execute {
pub command: String,
}
#[derive(Clap)]
pub struct Say {
pub message: String,
}
#[derive(Clap)]
pub struct SaveAll {
#[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)
}
}