Skip to content

Commit

Permalink
arg: update code to work with current Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
vks committed Dec 10, 2014
1 parent f3d787a commit c7108e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/staging/arg/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::os;
fn main() {
let args = os::args();
// The first argument is the path that was used to call the program.
println!("My path is {}.", args.get(0));
println!("My path is {}.", args[0]);
// The rest of the arguments are the passed command line parameters.
// Call the program like this:
// $ ./args arg1 arg2
Expand Down
8 changes: 4 additions & 4 deletions examples/staging/arg/getopts/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static VERSION: &'static str = "1.0.0";

fn main() {
let args = os::args();
let program = args.get(0).as_slice();
let ref program = args[0];

// Set possible flags.
// The first argument to `optflag` is the short flag name.
Expand All @@ -20,7 +20,7 @@ fn main() {
getopts::optflag("V", "version", "output version information and exit"),
];

let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
println!("{}", f);
Expand All @@ -39,7 +39,7 @@ fn main() {
println!(" {} [SHORT-OPTION]... [STRING]...", program);
println!(" {} LONG-OPTION", program);
println!("");
println(getopts::usage("Echo the STRING(s) to standard output.", opts)
println(getopts::usage("Echo the STRING(s) to standard output.", &opts)
.as_slice());
return;
}
Expand All @@ -53,7 +53,7 @@ fn main() {
//^ `matches.free` contains all the arguments that are not options.
let string = matches.free.connect(" ");
print(string.as_slice());
}
}

if !matches.opt_present("n") {
println!("")
Expand Down
4 changes: 2 additions & 2 deletions examples/staging/arg/getopts/testopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() {
// Use `optmulti`, `optflagmulti` if options can occur multiple times.
];

let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
println!("{}", f);
Expand All @@ -29,7 +29,7 @@ fn main() {
};
//^ Use `matches.opt_default` if you need a default (`opflagopt`).
// Use `matches.opt_count` if you need to count how many were matched (`*multi`).

println!("a={}, b={}, c=\"{}\"", a, b, c);
if !matches.free.is_empty() {
println!("free arguments: {}", matches.free);
Expand Down

0 comments on commit c7108e4

Please sign in to comment.