Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use std::env::args;
use std::io::{Error, Read};
use std::fs::File;
fn run(filename : &str) -> Result<(), Error> {
let mut f = try!(File::open(filename));
let mut s = String::new();
try!(f.read_to_string(&mut s));
println!("{}", s);
return Ok(());
}
fn usage() {
println!("To use:\nprog <filename>");
}
fn main() {
let mut arglist = args().skip(1);
match arglist.next() {
Some(ref filename) if arglist.count() == 0 => {
println!("Loading configuration from {}.", filename);
match run(filename) {
Ok(_) => return (),
Err(e) => println!("Error: {}", e)
}
}
_ => usage()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.