use std::path::PathBuf;
use facet::Facet;
#[derive(Facet, Debug)]
struct Config {
host: String,
port: u16,
timeout_secs: u64,
tls: Option<TlsConfig>,
allowed_origins: Vec<String>,
}
#[derive(Facet, Debug)]
struct TlsConfig {
cert: PathBuf,
key: PathBuf,
}
fn main() {
if std::env::args().nth(1).as_deref() == Some("@dump-styx-schema") {
print_schema();
return;
}
println!("This is myapp. Use @dump-styx-schema to dump the config schema.");
println!();
println!("Example config (config.styx):");
println!();
println!(" @schema {{source crate:myapp-config@1, cli myapp}}");
println!();
println!(" host localhost");
println!(" port 8080");
println!(" timeout_secs 30");
}
fn print_schema() {
print!(
r#"@meta {{
crate myapp-config
version {version}
bin myapp
}}
/// Server configuration.
Config @object {{
/// Hostname or IP address to bind to.
host @default(localhost @string)
/// Port number (1-65535).
port @default(8080 @int{{ min 1, max 65535 }})
/// Request timeout in seconds.
timeout_secs @default(30 @int)
/// TLS configuration (optional).
tls @optional(TlsConfig)
/// Allowed origins for CORS.
allowed_origins @default(() @list(@string))
}}
/// TLS certificate configuration.
TlsConfig @object {{
/// Path to certificate file.
cert @string
/// Path to private key file.
key @string
}}
"#,
version = env!("CARGO_PKG_VERSION")
);
}