auto merge of #4827 : mcpherrinm/rust/master, r=catamorphism

It seems to me the library needs more work to be done, but having a non-compilable sample program seems like bad news.
This commit is contained in:
bors 2013-02-09 17:28:04 -08:00
commit 2fc1f41d0d
1 changed files with 39 additions and 37 deletions

View File

@ -29,25 +29,27 @@
* The following example shows simple command line parsing for an application
* that requires an input file to be specified, accepts an optional output
* file name following -o, and accepts both -h and --help as optional flags.
* extern mod std;
* use std::getopts::*;
*
* use std;
* import std::getopts::{optopt,optflag,getopts,opt_present,opt_maybe_str,
* fail_str};
*
* fn do_work(in: str, out: Option<str>) {
* // ...
* fn do_work(in: &str, out: Option<~str>) {
* io::println(in);
* io::println(match out {
* Some(move x) => x,
* None => ~"No Output"
* });
* }
*
* fn print_usage(program: str) {
* io::println("Usage: " + program + " [options]");
* fn print_usage(program: &str, _opts: &[std::getopts::Opt]) {
* io::println(fmt!("Usage: %s [options]", program));
* io::println("-o\t\tOutput");
* io::println("-h --help\tUsage");
* }
*
* fn main(args: ~[str]) {
* check !args.is_empty()
* fn main() {
* let args = os::args();
*
* let program : str = vec::head(args);
* let program = copy args[0];
*
* let opts = ~[
* optopt("o"),
@ -55,18 +57,18 @@
* optflag("help")
* ];
* let matches = match getopts(vec::tail(args), opts) {
* result::ok(m) { m }
* result::err(f) { die!(fail_str(f)) }
* result::Ok(m) => { m }
* result::Err(f) => { fail fail_str(f) }
* };
* if opt_present(matches, "h") || opt_present(matches, "help") {
* print_usage(program);
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
* print_usage(program, opts);
* return;
* }
* let output = opt_maybe_str(matches, "o");
* let input = if !matches.free.is_empty() {
* let output = opt_maybe_str(&matches, "o");
* let input: &str = if !matches.free.is_empty() {
* matches.free[0]
* } else {
* print_usage(program);
* print_usage(program, opts);
* return;
* };
* do_work(input, output);