Skip to content

Fix formatting and errors in std::getopts example. #5308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/libstd/getopts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -29,8 +29,10 @@
* 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::*;
*
* ```
* extern mod std;
* use std::getopts::*;
*
* fn do_work(in: &str, out: Option<~str>) {
* io::println(in);
Expand Down Expand Up @@ -58,21 +60,22 @@
* ];
* let matches = match getopts(vec::tail(args), opts) {
* result::Ok(m) => { m }
* result::Err(f) => { fail fail_str(f) }
* result::Err(f) => { fail!(fail_str(f)) }
* };
* if opt_present(&matches, "h") || opt_present(&matches, "help") {
* print_usage(program, opts);
* return;
* }
* let output = opt_maybe_str(&matches, "o");
* let input: &str = if !matches.free.is_empty() {
* matches.free[0]
* copy matches.free[0]
* } else {
* print_usage(program, opts);
* return;
* };
* do_work(input, output);
* }
* ```
*/

use core::cmp::Eq;
Expand Down