coreutils/mkmain.rs

43 lines
959 B
Rust
Raw Normal View History

#![feature(exit_status)]
use std::env;
use std::io::Write;
use std::fs::File;
static TEMPLATE: &'static str = "\
2015-03-08 18:09:41 +00:00
#![feature(exit_status)]
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
use std::env;
use uu@UTIL_CRATE@::uumain;
fn main() {
2015-02-13 19:57:47 +00:00
env::set_exit_status(uumain(env::args().collect()));
}
";
fn main() {
2015-02-13 19:57:47 +00:00
let args : Vec<String> = env::args().collect();
if args.len() != 3 {
println!("usage: mkbuild <crate> <outfile>");
env::set_exit_status(1);
return;
}
let crat = match &args[1][..] {
"false" => "uufalse",
"test" => "uutest",
"true" => "uutrue",
_ => &args[1][..],
};
let outfile = &args[2][..];
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
match File::create(outfile) {
Ok(mut out) => match out.write_all(main.as_bytes()) {
Err(e) => panic!("{}", e),
_ => (),
},
2014-10-30 09:06:47 +00:00
Err(e) => panic!("{}", e),
}
}