feat: Make init check if the target is non-empty
This commit is contained in:
parent
617acba799
commit
f408a32d64
|
@ -1,5 +1,5 @@
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::{bail, ensure, Context, Result};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use super::GlobalArgs;
|
use super::GlobalArgs;
|
||||||
|
@ -10,13 +10,26 @@ pub struct InitArgs {
|
||||||
/// Domain name to use
|
/// Domain name to use
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub doman_name: Option<String>,
|
pub doman_name: Option<String>,
|
||||||
|
/// Force initialization
|
||||||
|
#[arg(long, short)]
|
||||||
|
pub force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InitArgs {
|
impl InitArgs {
|
||||||
/// Run the init command
|
/// Run the init command
|
||||||
#[instrument]
|
#[instrument]
|
||||||
pub fn run(self, _globals: GlobalArgs) -> Result<()> {
|
pub fn run(self, globals: GlobalArgs) -> Result<()> {
|
||||||
println!("Hello world!");
|
// Get the site directory
|
||||||
Ok(())
|
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!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue