|
30 | 30 | //! file name following `-o`, and accepts both `-h` and `--help` as optional flags.
|
31 | 31 | //!
|
32 | 32 | //! ```{.rust}
|
| 33 | +//! #![feature(rustc_private)] |
| 34 | +//! |
33 | 35 | //! extern crate getopts;
|
34 | 36 | //! use getopts::{optopt,optflag,getopts,OptGroup,usage};
|
35 |
| -//! use std::os; |
| 37 | +//! use std::env; |
36 | 38 | //!
|
37 | 39 | //! fn do_work(inp: &str, out: Option<String>) {
|
38 | 40 | //! println!("{}", inp);
|
|
44 | 46 | //!
|
45 | 47 | //! fn print_usage(program: &str, opts: &[OptGroup]) {
|
46 | 48 | //! let brief = format!("Usage: {} [options]", program);
|
47 |
| -//! print!("{}", usage(brief, opts)); |
| 49 | +//! print!("{}", usage(&brief, opts)); |
48 | 50 | //! }
|
49 | 51 | //!
|
50 | 52 | //! fn main() {
|
51 |
| -//! let args: Vec<String> = os::args(); |
| 53 | +//! let args: Vec<String> = env::args().collect(); |
52 | 54 | //!
|
53 | 55 | //! let program = args[0].clone();
|
54 | 56 | //!
|
55 | 57 | //! let opts = &[
|
56 | 58 | //! optopt("o", "", "set output file name", "NAME"),
|
57 | 59 | //! optflag("h", "help", "print this help menu")
|
58 | 60 | //! ];
|
59 |
| -//! let matches = match getopts(args[1..], opts) { |
| 61 | +//! let matches = match getopts(&args[1..], opts) { |
60 | 62 | //! Ok(m) => { m }
|
61 | 63 | //! Err(f) => { panic!(f.to_string()) }
|
62 | 64 | //! };
|
63 | 65 | //! if matches.opt_present("h") {
|
64 |
| -//! print_usage(program, opts); |
| 66 | +//! print_usage(&program, opts); |
65 | 67 | //! return;
|
66 | 68 | //! }
|
67 | 69 | //! let output = matches.opt_str("o");
|
68 | 70 | //! let input = if !matches.free.is_empty() {
|
69 | 71 | //! matches.free[0].clone()
|
70 | 72 | //! } else {
|
71 |
| -//! print_usage(program, opts); |
| 73 | +//! print_usage(&program, opts); |
72 | 74 | //! return;
|
73 | 75 | //! };
|
74 |
| -//! do_work(input, output); |
| 76 | +//! do_work(&input, output); |
75 | 77 | //! }
|
76 | 78 | //! ```
|
77 | 79 |
|
|
88 | 90 | #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
89 | 91 | html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
90 | 92 | html_root_url = "https://doc.rust-lang.org/nightly/",
|
91 |
| - html_playground_url = "https://play.rust-lang.org/")] |
| 93 | + html_playground_url = "https://play.rust-lang.org/", |
| 94 | + test(attr(deny(warnings))))] |
92 | 95 |
|
93 | 96 | #![deny(missing_docs)]
|
94 | 97 | #![feature(staged_api)]
|
|
0 commit comments