aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/bin.rs10
-rw-r--r--src/parser.rs7
3 files changed, 14 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 103576e..3dfc17d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -31,6 +31,7 @@ pest_derive = { git = 'https://github.com/pest-parser/pest' }
serde = '1.0.80'
serde_derive = '1.0.80'
serde_json = '1.0.33'
+serde-xml-rs = '0.2.1'
quicli = '0.3.1'
structopt = '0.2.13'
diff --git a/src/bin.rs b/src/bin.rs
index e203356..0422032 100644
--- a/src/bin.rs
+++ b/src/bin.rs
@@ -6,18 +6,21 @@ use structopt::StructOpt;
use clap::{_clap_count_exprs, arg_enum};
use quicli::{main, fs::read_file, prelude::Verbosity};
-use self::parser::serialize_json;
+use self::parser::{
+ serialize_json,
+ serialize_xml,
+};
arg_enum! {
#[derive(Debug)]
- enum Format { json }
+ enum Format { json, xml }
}
#[derive(Debug, StructOpt)]
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
struct Cli {
#[structopt(
- long = "format", short = "f", default_value = "json",
+ long = "format", short = "f", default_value = "json", // xml is pretty defunct…
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
)]
format: Format,
@@ -31,5 +34,6 @@ main!(|args: Cli, log_level: verbosity| {
let stdout = std::io::stdout();
match args.format {
Format::json => serialize_json(&content, stdout)?,
+ Format::xml => serialize_xml (&content, stdout)?,
}
});
diff --git a/src/parser.rs b/src/parser.rs
index 69ead45..a75d2a1 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -125,9 +125,14 @@ pub fn parse(source: &str) -> Result<Document, Error> {
}
-/// only until we can serialize DocumentTrees
pub fn serialize_json<W>(source: &str, stream: W) -> Result<(), Error> where W: Write {
let parsed = parse(source)?;
serde_json::to_writer(stream, &parsed)?;
Ok(())
}
+
+pub fn serialize_xml<W>(source: &str, stream: W) -> Result<(), Error> where W: Write {
+ let parsed = parse(source)?;
+ serde_xml_rs::serialize(&parsed, stream)?;
+ Ok(())
+}