Skip to content

Instantly share code, notes, and snippets.

@KMahoney
Created June 13, 2015 12:02
Show Gist options
  • Save KMahoney/96a54391dc4376843cea to your computer and use it in GitHub Desktop.
Save KMahoney/96a54391dc4376843cea to your computer and use it in GitHub Desktop.
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