| 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 | #![recursion_limit="256"]
pub mod document_tree;
pub mod parser;
pub mod target;
use structopt::StructOpt;
use clap::{_clap_count_exprs, arg_enum};
use quicli::{
    fs::read_file,
    prelude::{CliResult,Verbosity},
};
use self::parser::{
    serialize_json,
    serialize_xml,
};
arg_enum! {
    #[derive(Debug)]
    #[allow(non_camel_case_types)]
    enum Format { json, xml }
}
#[derive(Debug, StructOpt)]
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
struct Cli {
    #[structopt(
        long = "format", short = "f", default_value = "json",  // xml is pretty defunct…
        raw(possible_values = "&Format::variants()", case_insensitive = "true"),
    )]
    format: Format,
    file: String,
    #[structopt(flatten)]
    verbosity: Verbosity,
}
fn main() -> CliResult {
    let args = Cli::from_args();
    args.verbosity.setup_env_logger("rst")?;
    
    let content = read_file(args.file)?;
    let stdout = std::io::stdout();
    match args.format {
        Format::json => serialize_json(&content, stdout)?,
        Format::xml  => serialize_xml (&content, stdout)?,
    }
    Ok(())
}
 |