Created
June 13, 2015 12:02
-
-
Save KMahoney/96a54391dc4376843cea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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