Closed
Description
I'm new to Rust, so it's possible I'm doing something wrong, but I can't get std::getopt::opts_str to work for any argument but the first one given (I'm running Rust 0.6). I've tried some other permutations, but here's a minimal test case:
extern mod std;
use std::getopts::*;
fn main() {
let args = os::args();
let opts = ~[
optopt("a"), optopt("arg")
];
let matches = match getopts(vec::tail(args), opts) {
result::Ok(m) => { m }
result::Err(f) => { io::println(fail_str(f)); return }
};
if opts_present(&matches, [~"a", ~"arg"]) {
io::println(fmt!("Argument `%s`", opts_str(&matches, [~"a", ~"arg"])));
return;
}
}
and here's the output of some invocations (the expected result would be for the second line to output the same as first):
% rustc test.rs
% ./test -a foo
Argument `foo`
% ./test --arg foo
rust: task failed at 'index out of bounds: the len is 0 but the index is 0', /home/aaron/Downloads/rust-0.6/src/libstd/getopts.rs:360