Add a "check-config" command to validate config files & tests for it

This commit is contained in:
Andreas Fuchs 2024-10-04 10:49:08 -04:00
parent 70ee206031
commit 26ba489aa3
24 changed files with 492 additions and 0 deletions

View file

@ -12,6 +12,7 @@ use crate::{
error, observability,
};
mod check_config;
mod serve;
/// Command line arguments
@ -29,6 +30,18 @@ pub(crate) struct Args {
pub(crate) enum Command {
/// Run the server.
Serve(ServeArgs),
/// Check the configuration file for syntax and semantic errors.
CheckConfig(CheckConfigArgs),
}
#[derive(clap::Args)]
pub(crate) struct CheckConfigArgs {
#[clap(flatten)]
config: ConfigArg,
#[clap(flatten)]
observability: ObservabilityArgs,
}
/// Wrapper for the `--config` arg.
@ -83,6 +96,9 @@ impl Args {
match self.command {
Command::Serve(args) => serve::run(args).await?,
Command::CheckConfig(args) => {
check_config::run(args.config).await?;
}
}
Ok(())
}
@ -93,6 +109,10 @@ impl Command {
// All subcommands other than `serve` should return `Some`. Keep these
// match arms sorted by the enum variant name.
match self {
Command::CheckConfig(args) => Some((
args.observability.log_format,
args.observability.log_filter.clone(),
)),
Command::Serve(_) => None,
}
}