diff --git a/src/bin/cli/init.rs b/src/bin/cli/init.rs index 7aaf36a..f5bbf7c 100644 --- a/src/bin/cli/init.rs +++ b/src/bin/cli/init.rs @@ -1,5 +1,5 @@ use clap::Args; -use color_eyre::eyre::Result; +use color_eyre::eyre::{bail, ensure, Context, Result}; use tracing::instrument; use super::GlobalArgs; @@ -10,13 +10,26 @@ pub struct InitArgs { /// Domain name to use #[arg(long, short)] pub doman_name: Option, + /// Force initialization + #[arg(long, short)] + pub force: bool, } impl InitArgs { /// Run the init command #[instrument] - pub fn run(self, _globals: GlobalArgs) -> Result<()> { - println!("Hello world!"); - Ok(()) + pub fn run(self, globals: GlobalArgs) -> Result<()> { + // Get the site directory + let site_dir = globals.site_path().context("Failed getting site dir")?; + // Check to see if the directory is non-empty + let children = site_dir.read_dir().map(Iterator::count).unwrap_or(0); + if !(children == 0 || self.force) { + bail!( + "Site directory ({:?}) is non empty, pass -f/--force to initalize anyway", + site_dir + ); + } + println!("Initalizing new site in {}", site_dir.to_string_lossy()); + todo!() } }