Skip to content

Commit 2fc1f41

Browse files
committed
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.
2 parents d6442e9 + 0a062b5 commit 2fc1f41

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

src/libstd/getopts.rs

+39-37
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,50 @@
2929
* The following example shows simple command line parsing for an application
3030
* that requires an input file to be specified, accepts an optional output
3131
* file name following -o, and accepts both -h and --help as optional flags.
32+
* extern mod std;
33+
* use std::getopts::*;
3234
*
33-
* use std;
34-
* import std::getopts::{optopt,optflag,getopts,opt_present,opt_maybe_str,
35-
* fail_str};
35+
* fn do_work(in: &str, out: Option<~str>) {
36+
* io::println(in);
37+
* io::println(match out {
38+
* Some(move x) => x,
39+
* None => ~"No Output"
40+
* });
41+
* }
3642
*
37-
* fn do_work(in: str, out: Option<str>) {
38-
* // ...
39-
* }
43+
* fn print_usage(program: &str, _opts: &[std::getopts::Opt]) {
44+
* io::println(fmt!("Usage: %s [options]", program));
45+
* io::println("-o\t\tOutput");
46+
* io::println("-h --help\tUsage");
47+
* }
4048
*
41-
* fn print_usage(program: str) {
42-
* io::println("Usage: " + program + " [options]");
43-
* io::println("-o\t\tOutput");
44-
* io::println("-h --help\tUsage");
45-
* }
49+
* fn main() {
50+
* let args = os::args();
4651
*
47-
* fn main(args: ~[str]) {
48-
* check !args.is_empty()
52+
* let program = copy args[0];
4953
*
50-
* let program : str = vec::head(args);
51-
*
52-
* let opts = ~[
53-
* optopt("o"),
54-
* optflag("h"),
55-
* optflag("help")
56-
* ];
57-
* let matches = match getopts(vec::tail(args), opts) {
58-
* result::ok(m) { m }
59-
* result::err(f) { die!(fail_str(f)) }
60-
* };
61-
* if opt_present(matches, "h") || opt_present(matches, "help") {
62-
* print_usage(program);
63-
* return;
64-
* }
65-
* let output = opt_maybe_str(matches, "o");
66-
* let input = if !matches.free.is_empty() {
67-
* matches.free[0]
68-
* } else {
69-
* print_usage(program);
70-
* return;
71-
* };
72-
* do_work(input, output);
73-
* }
54+
* let opts = ~[
55+
* optopt("o"),
56+
* optflag("h"),
57+
* optflag("help")
58+
* ];
59+
* let matches = match getopts(vec::tail(args), opts) {
60+
* result::Ok(m) => { m }
61+
* result::Err(f) => { fail fail_str(f) }
62+
* };
63+
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
64+
* print_usage(program, opts);
65+
* return;
66+
* }
67+
* let output = opt_maybe_str(&matches, "o");
68+
* let input: &str = if !matches.free.is_empty() {
69+
* matches.free[0]
70+
* } else {
71+
* print_usage(program, opts);
72+
* return;
73+
* };
74+
* do_work(input, output);
75+
* }
7476
*/
7577

7678
use core::cmp::Eq;

0 commit comments

Comments
 (0)