-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsimple.rs
More file actions
34 lines (30 loc) · 768 Bytes
/
simple.rs
File metadata and controls
34 lines (30 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::io::Read;
use miette::IntoDiagnostic;
#[derive(knus::Decode, Debug)]
#[allow(dead_code)]
struct Plugin {
#[knus(argument)]
name: String,
#[knus(property)]
url: String,
#[knus(child, unwrap(argument))]
version: String,
}
#[derive(knus::Decode, Debug)]
#[allow(dead_code)]
struct Config {
#[knus(child, unwrap(argument))]
version: String,
#[knus(children(name = "plugin"))]
plugins: Vec<Plugin>,
}
fn main() -> miette::Result<()> {
let mut buf = String::new();
println!("Please type KDL document, press Return, Ctrl+D to finish");
std::io::stdin()
.read_to_string(&mut buf)
.into_diagnostic()?;
let cfg: Config = knus::parse("<stdin>", &buf)?;
println!("{:#?}", cfg);
Ok(())
}