add command to get the state of all rooms

This commit is contained in:
Charles Hall 2024-10-22 12:25:53 -07:00
parent 2f8e0e3e52
commit 33598a79b7
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
4 changed files with 183 additions and 0 deletions

View file

@ -13,6 +13,7 @@ use crate::{
};
mod check_config;
mod get_room_states;
mod serve;
/// Command line arguments
@ -33,6 +34,11 @@ pub(crate) enum Command {
/// Check the configuration file for syntax and semantic errors.
CheckConfig(CheckConfigArgs),
/// Write the state of all rooms as JSON to stdout.
///
/// This is primarily useful for debugging.
GetRoomStates(GetRoomStatesArgs),
}
#[derive(clap::Args)]
@ -88,6 +94,15 @@ pub(crate) struct ServeArgs {
pub(crate) config: ConfigArg,
}
#[derive(clap::Args)]
pub(crate) struct GetRoomStatesArgs {
#[clap(flatten)]
pub(crate) config: ConfigArg,
#[clap(flatten)]
observability: ObservabilityArgs,
}
impl Args {
pub(crate) async fn run(self) -> Result<(), error::Main> {
if let Some((format, filter)) = self.command.cli_observability_args() {
@ -99,6 +114,7 @@ impl Args {
Command::CheckConfig(args) => {
check_config::run(args.config).await?;
}
Command::GetRoomStates(args) => get_room_states::run(args).await?,
}
Ok(())
}
@ -113,6 +129,10 @@ impl Command {
args.observability.log_format,
args.observability.log_filter.clone(),
)),
Command::GetRoomStates(args) => Some((
args.observability.log_format,
args.observability.log_filter.clone(),
)),
Command::Serve(_) => None,
}
}