minify-html/src/main.rs

35 lines
1.1 KiB
Rust
Raw Normal View History

2019-12-25 04:44:51 -05:00
use std::fs::File;
2019-12-30 03:29:47 -05:00
use std::io::{Read, Write};
2019-12-25 07:29:18 -05:00
2019-12-25 04:44:51 -05:00
use structopt::StructOpt;
use hyperbuild::{hyperbuild_friendly, FriendlyError};
2019-12-25 04:44:51 -05:00
#[derive(StructOpt)]
struct Cli {
#[structopt(short, long, parse(from_os_str))]
src: std::path::PathBuf,
#[structopt(short, long, parse(from_os_str))]
out: std::path::PathBuf,
}
fn main() {
let args = Cli::from_args();
2019-12-25 07:29:18 -05:00
let mut code = Vec::<u8>::new();
let mut src_file = File::open(args.src).expect("could not open source file");
src_file.read_to_end(&mut code).expect("could not read source file");
match hyperbuild_friendly(&mut code) {
2019-12-25 07:29:18 -05:00
Ok(out_len) => {
let mut out_file = File::create(args.out).expect("could not open output file");
out_file.write_all(&code[..out_len]).expect("could not write to output file");
}
Err(FriendlyError { position, message, code_context }) => {
eprintln!("Failed at character {}:", position);
eprintln!("{}", message);
eprintln!("The output file has not been touched.");
eprintln!("-----");
eprintln!("{}", code_context);
2019-12-25 07:29:18 -05:00
}
};
2019-12-25 04:44:51 -05:00
}