summaryrefslogtreecommitdiff
path: root/src/bin/sp-meta.rs
blob: b90799916e70cfdb71ac21a0670941d3e9366e33 (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
use anyhow::Result;
use std::convert::TryFrom;
use std::path::PathBuf;

use structopt::StructOpt;

use subplot::Style;

mod cli;

use cli::{Metadata, OutputFormat};

#[derive(Debug, StructOpt)]
#[structopt(name = "sp-meta", about = "Show Subplot document metadata.")]
struct Opt {
    /// Form that you want the output to take
    #[structopt(short = "o", default_value = "plain", possible_values=&["plain", "json"])]
    output_format: OutputFormat,
    /// Input subplot document filename
    #[structopt(parse(from_os_str))]
    filename: PathBuf,
}

fn main() -> Result<()> {
    let opt = Opt::from_args();
    let mut doc = cli::load_document(&opt.filename, Style::default())?;
    let meta = Metadata::try_from(&mut doc)?;

    match opt.output_format {
        OutputFormat::Plain => meta.write_out(),
        OutputFormat::Json => println!("{}", serde_json::to_string_pretty(&meta)?),
    }

    Ok(())
}