openrr_apps_config/
config.rsuse std::{fs, path::PathBuf};
use anyhow::Result;
use clap::{Parser, ValueEnum};
use openrr_apps::utils::init_tracing;
use schemars::schema_for;
use serde::Deserialize;
use tracing::debug;
#[derive(Debug, Parser)]
#[clap(name = env!("CARGO_BIN_NAME"))]
struct Args {
#[clap(subcommand)]
subcommand: Subcommand,
}
#[derive(Debug, Parser)]
enum Subcommand {
Schema {
#[clap(value_enum, ignore_case = true)]
kind: ConfigKind,
},
Merge {
#[clap(long, value_parser)]
config_path: PathBuf,
#[clap(long)]
config: String,
},
}
#[derive(Debug, Clone, Copy, ValueEnum)]
enum ConfigKind {
RobotConfig,
RobotTeleopConfig,
}
#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum Config {
RobotConfig(#[allow(dead_code)] Box<openrr_apps::RobotConfig>),
RobotTeleopConfig(#[allow(dead_code)] Box<openrr_apps::RobotTeleopConfig>),
}
fn main() -> Result<()> {
init_tracing();
let args = Args::parse();
debug!(?args);
match args.subcommand {
Subcommand::Schema { kind } => {
let schema = match kind {
ConfigKind::RobotConfig => schema_for!(openrr_apps::RobotConfig),
ConfigKind::RobotTeleopConfig => schema_for!(openrr_apps::RobotTeleopConfig),
};
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
Subcommand::Merge {
config_path,
config: overwrite,
} => {
let s = &fs::read_to_string(config_path)?;
let s = &openrr_config::overwrite_str(s, &overwrite)?;
let _base: Config = toml::from_str(s)?;
println!("{s}");
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use clap::CommandFactory;
use super::*;
#[test]
fn assert_app() {
Args::command().debug_assert();
}
}