refactor: Move definition writing into separate function
This commit is contained in:
@@ -744,6 +744,7 @@ device_manager:schedule("0 0 20 * * *", function()
|
||||
bedroom_air_filter:set_on(false)
|
||||
end)
|
||||
|
||||
---@type Config
|
||||
return {
|
||||
fulfillment = {
|
||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||
|
||||
@@ -6,23 +6,33 @@ use tracing::{info, warn};
|
||||
|
||||
extern crate automation_devices;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
fn write_definitions(filename: &str, definitions: &str) -> std::io::Result<()> {
|
||||
let definitions_directory =
|
||||
std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")).join("definitions");
|
||||
fs::create_dir_all(&definitions_directory)?;
|
||||
|
||||
let mut file = File::create(definitions_directory.join(filename))?;
|
||||
|
||||
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
|
||||
file.write_all(definitions.as_bytes())?;
|
||||
|
||||
// Make sure we have a trailing new line
|
||||
if !definitions.ends_with("\n") {
|
||||
file.write_all(b"\n")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
for module in inventory::iter::<Module> {
|
||||
if let Some(definitions) = module.definitions() {
|
||||
info!(name = module.get_name(), "Generating definitions");
|
||||
|
||||
let filename = format!("{}.lua", module.get_name());
|
||||
let mut file = File::create(definitions_directory.join(filename))?;
|
||||
|
||||
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
|
||||
file.write_all(definitions.as_bytes())?;
|
||||
file.write_all(b"\n")?;
|
||||
write_definitions(&filename, &definitions)?;
|
||||
} else {
|
||||
warn!(name = module.get_name(), "No definitions");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user