use crate::{commands, error::Result};
use clap::{Parser, Subcommand};
#[derive(Subcommand, Debug, PartialEq)]
pub enum Commands {
Init {
name: Option<String>,
},
Build {
#[arg(short, long, default_value = "dist")]
dir: String,
},
Serve {
#[arg(short, long, default_value_t = 3000)]
port: u16,
},
}
#[derive(Parser, Debug, PartialEq)]
#[command(name = "zahuyach")]
#[command(about = "A static site generator for blogs")]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
impl Cli {
pub fn run(self) -> Result<String> {
match self.command {
Commands::Init { name } => commands::init::run(name.as_ref()),
Commands::Build { dir } => commands::build::run(dir),
Commands::Serve { port } => commands::serve::run(port),
}
}
pub fn get_command(&self) -> &Commands {
&self.command
}
}