From 32d660c23ca7d44da44112187f2efb18fa4077ed Mon Sep 17 00:00:00 2001 From: Philipp A Date: Tue, 20 Nov 2018 10:53:34 +0100 Subject: added silly xml serializing --- src/bin.rs | 10 +++++++--- src/parser.rs | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') 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 { } -/// only until we can serialize DocumentTrees pub fn serialize_json(source: &str, stream: W) -> Result<(), Error> where W: Write { let parsed = parse(source)?; serde_json::to_writer(stream, &parsed)?; Ok(()) } + +pub fn serialize_xml(source: &str, stream: W) -> Result<(), Error> where W: Write { + let parsed = parse(source)?; + serde_xml_rs::serialize(&parsed, stream)?; + Ok(()) +} -- cgit v1.2.3