summaryrefslogtreecommitdiffstats
path: root/src/bin.rs
blob: 7ab5cbca47b8ada65462c49866f41b36cb1c129f (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
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "mktoc")]
struct Cli {
    #[structopt()]
    file: String,

    #[structopt(long, short)]
    write: bool,
}

fn main() -> std::io::Result<()> {
    let opts = Cli::from_args();
    let file = &opts.file.to_owned();
    let res = mktoc::make_toc(file.to_string());
    if opts.write {
        std::fs::write(file, res.as_bytes())?;
    } else {
        println!("{}", res);
    }

    Ok(())
}