xous-core/svd2repl/src/main.rs
Sean Cross 74abf35a08 svd2repl: add program to generate a repl file
Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-19 14:12:01 +08:00

44 lines
1.3 KiB
Rust

mod generate;
use anyhow::Context;
use clap::{App, Arg};
use std::fs::File;
use std::io::{Read, Write};
fn main() -> anyhow::Result<()> {
let matches = App::new("svd2repl")
.about("Generate a Rebide Platform description from SVD files")
.arg(
Arg::with_name("input")
.help("Input SVD file")
.short("i")
.takes_value(true)
.value_name("FILE"),
)
.arg(
Arg::with_name("output")
.help("Output .repl file or directory")
.short("o")
.takes_value(true)
.value_name("FILE"),
)
.version(concat!(
env!("CARGO_PKG_VERSION"),
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
))
.get_matches();
let src: Box<dyn Read> = match matches.value_of("input") {
Some(file) => Box::new(File::open(file).context("Cannot open the SVD file")?),
None => Box::new(std::io::stdin()),
};
let mut dest: Box<dyn Write> = match matches.value_of("output") {
None => Box::new(std::io::stdout()),
Some(path) => Box::new(File::create(path).context("Cannot open destination file")?),
};
generate::generate(src, &mut dest).context("Cannot generate output file")?;
Ok(())
}