Created
March 23, 2015 22:42
-
-
Save adamhjk/49751914f36ee609694f to your computer and use it in GitHub Desktop.
sysadmin crate?
This file contains hidden or 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
extern crate sysadmin; | |
use sysadmin::{file}; | |
// Use docopt.rs to generate the cli arguments, process ARGV, | |
// and set up a main() that runs the run function. Checks the | |
// results and runs at_exit with nice error messages and a variety | |
// of error codes | |
cli!( | |
"Usage: wc [--lines] <file> | |
-l, --lines Show the count of lines | |
" | |
); | |
fn run(args: Args) -> Result<SysadminError> { | |
let Args{cmd_file: filename, flag_lines: lines} = args; | |
// Raise good looking errors for IO, file not found, etc | |
// We would only have to make these once | |
let file = try!(file::open(&filename)); | |
if flag_lines { | |
lines = try!(file.split(b'\n')); | |
prinln!("lines: {}", lines.count()); | |
} else { | |
spaces = try!(file.split(b' ')); | |
println!("words: {}", spaces.count()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment