use utils::ExitStatus;
use std::process;
pub struct Prog {
pub name: &'static str,
pub vers: &'static str,
pub yr: &'static str,
}
impl Prog {
pub fn copyright(&self, license: &str, auth: &[&str]) {
print!("{} {}\n{}", &self.name, &self.vers, license);
print!("Written by ");
for pers in auth.iter() {
print!("{} ", pers);
}
print!("\n");
}
pub fn prog_try(&self) {
println!("{}: Missing arguments\n\
Try '{} --help' for more information", &self.name, &self.name);
&self.exit(ExitStatus::ArgError);
}
pub fn exit(&self, status: ExitStatus) {
process::exit(status as i32);
}
}
#[test]
fn test_prog() {
let prog = Prog { name: "util", vers: "0.1.0", yr: "2015" };
assert_eq!(prog.name, "util");
assert_eq!(prog.vers, "0.1.0");
assert_eq!(prog.yr, "2015");
}
#[test]
fn test_prog_copyright() {
let prog = Prog { name: "util", vers: "0.1.0", yr: "2015" };
prog.copyright(
"Copyright (C) 2015 util developers\n\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n", &["Author"]);
}