diff --git a/Cargo.lock b/Cargo.lock index 142c38c..03a313f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,7 @@ dependencies = [ "git-version", "google_home", "inventory", + "lua_typed", "mlua", "reqwest", "rumqttc", diff --git a/Cargo.toml b/Cargo.toml index 384f87f..bd2a927 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/definitions/config.lua b/definitions/config.lua new file mode 100644 index 0000000..dc070a5 --- /dev/null +++ b/definitions/config.lua @@ -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 diff --git a/src/bin/generate_definitions.rs b/src/bin/generate_definitions.rs index be95d04..2bdcd79 100644 --- a/src/bin/generate_definitions.rs +++ b/src/bin/generate_definitions.rs @@ -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("FulfillmentConfig 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(()) } diff --git a/src/config.rs b/src/config.rs index 190b2f2..34851b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, }