aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin.rs
blob: f8ee45b9419a91d6f217e42f3d1d42c3bf45fa89 (plain)
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
mod parser;


use pest::Parser;
use structopt::StructOpt;
use clap::{_clap_count_exprs, arg_enum};
use quicli::{main, fs::read_file, prelude::Verbosity};

use self::parser::{RstParser, Rule, serialize::PairsWrap};


arg_enum! {
    #[derive(Debug)]
    enum Format { json }
}

#[derive(Debug, StructOpt)]
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
struct Cli {
    #[structopt(
        long = "format", short = "f", default_value = "json",
        raw(possible_values = "&Format::variants()", case_insensitive = "true"),
    )]
    format: Format,
    file: String,
    #[structopt(flatten)]
    verbosity: Verbosity,
}

main!(|args: Cli, log_level: verbosity| {
    let content = read_file(args.file)?;
    let parsed = RstParser::parse(Rule::doc, &content)?;
    let stdout = std::io::stdout();
    match args.format {
        Format::json => serde_json::to_writer(stdout, &PairsWrap(parsed))?,
    }
});