feat: Validate subcommand
This commit is contained in:
parent
8bdfcaa1d8
commit
fc62d8c30c
|
@ -4,9 +4,12 @@ use snafu::{ensure, ResultExt, Snafu};
|
||||||
use std::{env::current_dir, path::PathBuf};
|
use std::{env::current_dir, path::PathBuf};
|
||||||
|
|
||||||
mod init;
|
mod init;
|
||||||
|
mod validate;
|
||||||
|
|
||||||
pub use init::InitArgs;
|
pub use init::InitArgs;
|
||||||
|
|
||||||
|
use self::validate::ValidateArgs;
|
||||||
|
|
||||||
/// Error encountered while parsing CLI
|
/// Error encountered while parsing CLI
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum CliError {
|
pub enum CliError {
|
||||||
|
@ -81,6 +84,8 @@ impl GlobalArgs {
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Initialize a site
|
/// Initialize a site
|
||||||
Init(InitArgs),
|
Init(InitArgs),
|
||||||
|
/// Valiate the structure and configuration of a site
|
||||||
|
Validate(ValidateArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
|
@ -88,6 +93,7 @@ impl Command {
|
||||||
pub fn run(self, globals: GlobalArgs) -> Result<()> {
|
pub fn run(self, globals: GlobalArgs) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Command::Init(args) => args.run(globals),
|
Command::Init(args) => args.run(globals),
|
||||||
|
Command::Validate(args) => args.run(globals),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
use clap::Args;
|
||||||
|
use color_eyre::eyre::{Context, Result};
|
||||||
|
use stranger_site_gen::site::Site;
|
||||||
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
|
use super::GlobalArgs;
|
||||||
|
|
||||||
|
/// Arguments for the validate subcommand
|
||||||
|
#[derive(Args, Debug)]
|
||||||
|
pub struct ValidateArgs {
|
||||||
|
/// Dump the site configuration to the console
|
||||||
|
#[arg(long, short)]
|
||||||
|
pub dump_config: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ValidateArgs {
|
||||||
|
/// Run the validate command
|
||||||
|
#[instrument]
|
||||||
|
pub fn run(self, globals: GlobalArgs) -> Result<()> {
|
||||||
|
// Get the site directory
|
||||||
|
let site_dir = globals.site_path().context("Failed getting site dir")?;
|
||||||
|
debug!(?site_dir, "Attempting to load site directory");
|
||||||
|
// Attempt to load the site
|
||||||
|
let site = Site::read(&site_dir).context("Failed to validate site!");
|
||||||
|
// If requested, dump the configuration to the console
|
||||||
|
println!("Site is valid");
|
||||||
|
if self.dump_config {
|
||||||
|
println!("Site state:");
|
||||||
|
println!("{:#?}", site);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue