feat: Generate definitions for config

This commit is contained in:
2025-10-17 03:15:27 +02:00
parent b557afe2fc
commit 84e8942fc9
5 changed files with 34 additions and 2 deletions

1
Cargo.lock generated
View File

@@ -99,6 +99,7 @@ dependencies = [
"git-version",
"google_home",
"inventory",
"lua_typed",
"mlua",
"reqwest",
"rumqttc",

View File

@@ -77,6 +77,7 @@ config = { version = "0.15.15", default-features = false, features = [
] }
git-version = "0.3.9"
google_home = { workspace = true }
lua_typed = { workspace = true }
inventory = { workspace = true }
mlua = { workspace = true }
reqwest = { workspace = true }

12
definitions/config.lua Normal file
View File

@@ -0,0 +1,12 @@
-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED
---@meta
---@class FulfillmentConfig
---@field openid_url string
---@field ip string?
---@field port integer?
local FulfillmentConfig
---@class Config
---@field fulfillment FulfillmentConfig
local Config

View File

@@ -1,7 +1,9 @@
use std::fs::{self, File};
use std::io::Write;
use automation::config::{Config, FulfillmentConfig};
use automation_lib::Module;
use lua_typed::Typed;
use tracing::{info, warn};
extern crate automation_devices;
@@ -24,6 +26,17 @@ fn write_definitions(filename: &str, definitions: &str) -> std::io::Result<()> {
Ok(())
}
fn config_definitions() -> String {
let mut output = "---@meta\n\n".to_string();
output +=
&FulfillmentConfig::generate_full().expect("FulfillmentConfig should have a definition");
output += "\n";
output += &Config::generate_full().expect("Config should have a definition");
output
}
fn main() -> std::io::Result<()> {
tracing_subscriber::fmt::init();
@@ -38,5 +51,7 @@ fn main() -> std::io::Result<()> {
}
}
write_definitions("config.lua", &config_definitions())?;
Ok(())
}

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddr};
use lua_typed::Typed;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
@@ -17,16 +18,18 @@ fn default_entrypoint() -> String {
"./config.lua".into()
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Typed)]
pub struct FulfillmentConfig {
pub openid_url: String,
#[serde(default = "default_fulfillment_ip")]
#[typed(default)]
pub ip: Ipv4Addr,
#[serde(default = "default_fulfillment_port")]
#[typed(default)]
pub port: u16,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Typed)]
pub struct Config {
pub fulfillment: FulfillmentConfig,
}