提交 1fb08f11 编写于 作者: P Patrick Walton

libgetopts: Remove all uses of `~str` from `libgetopts`

上级 28bcef85
......@@ -101,11 +101,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
}
let matches =
&match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
groups.as_slice()) {
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
......@@ -146,7 +142,9 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
mode: FromStr::from_str(matches.opt_str("mode")
.unwrap()
.as_slice()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
......@@ -154,7 +152,8 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
ratchet_metrics:
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
matches.opt_str("ratchet-noise-percent")
.and_then(|s| from_str::<f64>(s.as_slice())),
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
host_rustcflags: matches.opt_str("host-rustcflags")
.map(|x| x.to_strbuf()),
......
......@@ -34,7 +34,7 @@
//! use getopts::{optopt,optflag,getopts,OptGroup};
//! use std::os;
//!
//! fn do_work(inp: &str, out: Option<~str>) {
//! fn do_work(inp: &str, out: Option<StrBuf>) {
//! println!("{}", inp);
//! match out {
//! Some(x) => println!("{}", x),
......@@ -49,7 +49,9 @@
//! }
//!
//! fn main() {
//! let args = os::args();
//! let args: Vec<StrBuf> = os::args().iter()
//! .map(|x| x.to_strbuf())
//! .collect();
//!
//! let program = args.get(0).clone();
//!
......@@ -62,17 +64,17 @@
//! Err(f) => { fail!(f.to_err_msg()) }
//! };
//! if matches.opt_present("h") {
//! print_usage(program, opts);
//! print_usage(program.as_slice(), opts);
//! return;
//! }
//! let output = matches.opt_str("o");
//! let input: &str = if !matches.free.is_empty() {
//! let input = if !matches.free.is_empty() {
//! (*matches.free.get(0)).clone()
//! } else {
//! print_usage(program, opts);
//! print_usage(program.as_slice(), opts);
//! return;
//! };
//! do_work(input, output);
//! do_work(input.as_slice(), output);
//! }
//! ~~~
......@@ -99,7 +101,7 @@
pub enum Name {
/// A string representing the long name of an option.
/// For example: "help"
Long(~str),
Long(StrBuf),
/// A char representing the short name of an option.
/// For example: 'h'
Short(char),
......@@ -145,13 +147,13 @@ pub struct Opt {
#[deriving(Clone, Eq)]
pub struct OptGroup {
/// Short Name of the `OptGroup`
pub short_name: ~str,
pub short_name: StrBuf,
/// Long Name of the `OptGroup`
pub long_name: ~str,
pub long_name: StrBuf,
/// Hint
pub hint: ~str,
pub hint: StrBuf,
/// Description
pub desc: ~str,
pub desc: StrBuf,
/// Whether it has an argument
pub hasarg: HasArg,
/// How often it can occur
......@@ -161,7 +163,7 @@ pub struct OptGroup {
/// Describes wether an option is given at all or has a value.
#[deriving(Clone, Eq)]
enum Optval {
Val(~str),
Val(StrBuf),
Given,
}
......@@ -174,7 +176,7 @@ pub struct Matches {
/// Values of the Options that matched
vals: Vec<Vec<Optval> > ,
/// Free string fragments
pub free: Vec<~str>,
pub free: Vec<StrBuf>,
}
/// The type returned when the command line does not conform to the
......@@ -183,15 +185,15 @@ pub struct Matches {
#[deriving(Clone, Eq, Show)]
pub enum Fail_ {
/// The option requires an argument but none was passed.
ArgumentMissing(~str),
ArgumentMissing(StrBuf),
/// The passed option is not declared among the possible options.
UnrecognizedOption(~str),
UnrecognizedOption(StrBuf),
/// A required option is not present.
OptionMissing(~str),
OptionMissing(StrBuf),
/// A single occurence option is being used multiple times.
OptionDuplicated(~str),
OptionDuplicated(StrBuf),
/// There's an argument being passed to a non-argument option.
UnexpectedArgument(~str),
UnexpectedArgument(StrBuf),
}
/// The type of failure that occurred.
......@@ -213,14 +215,14 @@ fn from_str(nm: &str) -> Name {
if nm.len() == 1u {
Short(nm.char_at(0u))
} else {
Long(nm.to_owned())
Long(nm.to_strbuf())
}
}
fn to_str(&self) -> ~str {
fn to_str(&self) -> StrBuf {
match *self {
Short(ch) => ch.to_str(),
Long(ref s) => s.to_owned()
Short(ch) => ch.to_str().to_strbuf(),
Long(ref s) => s.to_strbuf()
}
}
}
......@@ -246,7 +248,7 @@ pub fn long_to_short(&self) -> Opt {
aliases: Vec::new()
},
(1,0) => Opt {
name: Short(short_name.char_at(0)),
name: Short(short_name.as_slice().char_at(0)),
hasarg: hasarg,
occur: occur,
aliases: Vec::new()
......@@ -257,7 +259,7 @@ pub fn long_to_short(&self) -> Opt {
occur: occur,
aliases: vec!(
Opt {
name: Short(short_name.char_at(0)),
name: Short(short_name.as_slice().char_at(0)),
hasarg: hasarg,
occur: occur,
aliases: Vec::new()
......@@ -297,9 +299,10 @@ pub fn opt_count(&self, nm: &str) -> uint {
}
/// Returns true if any of several options were matched.
pub fn opts_present(&self, names: &[~str]) -> bool {
pub fn opts_present(&self, names: &[StrBuf]) -> bool {
for nm in names.iter() {
match find_opt(self.opts.as_slice(), Name::from_str(*nm)) {
match find_opt(self.opts.as_slice(),
Name::from_str(nm.as_slice())) {
Some(id) if !self.vals.get(id).is_empty() => return true,
_ => (),
};
......@@ -308,9 +311,9 @@ pub fn opts_present(&self, names: &[~str]) -> bool {
}
/// Returns the string argument supplied to one of several matching options or `None`.
pub fn opts_str(&self, names: &[~str]) -> Option<~str> {
pub fn opts_str(&self, names: &[StrBuf]) -> Option<StrBuf> {
for nm in names.iter() {
match self.opt_val(*nm) {
match self.opt_val(nm.as_slice()) {
Some(Val(ref s)) => return Some(s.clone()),
_ => ()
}
......@@ -322,8 +325,8 @@ pub fn opts_str(&self, names: &[~str]) -> Option<~str> {
/// option.
///
/// Used when an option accepts multiple values.
pub fn opt_strs(&self, nm: &str) -> Vec<~str> {
let mut acc: Vec<~str> = Vec::new();
pub fn opt_strs(&self, nm: &str) -> Vec<StrBuf> {
let mut acc: Vec<StrBuf> = Vec::new();
let r = self.opt_vals(nm);
for v in r.iter() {
match *v {
......@@ -335,10 +338,10 @@ pub fn opt_strs(&self, nm: &str) -> Vec<~str> {
}
/// Returns the string argument supplied to a matching option or `None`.
pub fn opt_str(&self, nm: &str) -> Option<~str> {
pub fn opt_str(&self, nm: &str) -> Option<StrBuf> {
let vals = self.opt_vals(nm);
if vals.is_empty() {
return None::<~str>;
return None::<StrBuf>;
}
match vals.get(0) {
&Val(ref s) => Some((*s).clone()),
......@@ -352,12 +355,14 @@ pub fn opt_str(&self, nm: &str) -> Option<~str> {
/// Returns none if the option was not present, `def` if the option was
/// present but no argument was provided, and the argument if the option was
/// present and an argument was provided.
pub fn opt_default(&self, nm: &str, def: &str) -> Option<~str> {
pub fn opt_default(&self, nm: &str, def: &str) -> Option<StrBuf> {
let vals = self.opt_vals(nm);
if vals.is_empty() { return None; }
if vals.is_empty() {
return None;
}
match vals.get(0) {
&Val(ref s) => Some((*s).clone()),
_ => Some(def.to_owned())
_ => Some(def.to_strbuf())
}
}
......@@ -389,10 +394,10 @@ pub fn reqopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: hint.to_strbuf(),
desc: desc.to_strbuf(),
hasarg: Yes,
occur: Req
}
......@@ -403,10 +408,10 @@ pub fn optopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: hint.to_strbuf(),
desc: desc.to_strbuf(),
hasarg: Yes,
occur: Optional
}
......@@ -417,10 +422,10 @@ pub fn optflag(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: "".to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: "".to_strbuf(),
desc: desc.to_strbuf(),
hasarg: No,
occur: Optional
}
......@@ -432,10 +437,10 @@ pub fn optflagmulti(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: "".to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: "".to_strbuf(),
desc: desc.to_strbuf(),
hasarg: No,
occur: Multi
}
......@@ -446,10 +451,10 @@ pub fn optflagopt(short_name: &str, long_name: &str, desc: &str, hint: &str) ->
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: hint.to_strbuf(),
desc: desc.to_strbuf(),
hasarg: Maybe,
occur: Optional
}
......@@ -461,10 +466,10 @@ pub fn optmulti(short_name: &str, long_name: &str, desc: &str, hint: &str) -> Op
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: hint.to_strbuf(),
desc: desc.to_strbuf(),
hasarg: Yes,
occur: Multi
}
......@@ -480,10 +485,10 @@ pub fn opt(short_name: &str,
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
short_name: short_name.to_strbuf(),
long_name: long_name.to_strbuf(),
hint: hint.to_strbuf(),
desc: desc.to_strbuf(),
hasarg: hasarg,
occur: occur
}
......@@ -491,22 +496,22 @@ pub fn opt(short_name: &str,
impl Fail_ {
/// Convert a `Fail_` enum into an error string.
pub fn to_err_msg(self) -> ~str {
pub fn to_err_msg(self) -> StrBuf {
match self {
ArgumentMissing(ref nm) => {
format!("Argument to option '{}' missing.", *nm)
format_strbuf!("Argument to option '{}' missing.", *nm)
}
UnrecognizedOption(ref nm) => {
format!("Unrecognized option: '{}'.", *nm)
format_strbuf!("Unrecognized option: '{}'.", *nm)
}
OptionMissing(ref nm) => {
format!("Required option '{}' missing.", *nm)
format_strbuf!("Required option '{}' missing.", *nm)
}
OptionDuplicated(ref nm) => {
format!("Option '{}' given more than once.", *nm)
format_strbuf!("Option '{}' given more than once.", *nm)
}
UnexpectedArgument(ref nm) => {
format!("Option '{}' does not take an argument.", *nm)
format_strbuf!("Option '{}' does not take an argument.", *nm)
}
}
}
......@@ -517,44 +522,44 @@ pub fn to_err_msg(self) -> ~str {
/// On success returns `Ok(Opt)`. Use methods such as `opt_present`
/// `opt_str`, etc. to interrogate results. Returns `Err(Fail_)` on failure.
/// Use `to_err_msg` to get an error message.
pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result {
pub fn getopts(args: &[StrBuf], optgrps: &[OptGroup]) -> Result {
let opts: Vec<Opt> = optgrps.iter().map(|x| x.long_to_short()).collect();
let n_opts = opts.len();
fn f(_x: uint) -> Vec<Optval> { return Vec::new(); }
let mut vals = Vec::from_fn(n_opts, f);
let mut free: Vec<~str> = Vec::new();
let mut free: Vec<StrBuf> = Vec::new();
let l = args.len();
let mut i = 0;
while i < l {
let cur = args[i].clone();
let curlen = cur.len();
if !is_arg(cur) {
if !is_arg(cur.as_slice()) {
free.push(cur);
} else if cur == "--".to_owned() {
} else if cur.as_slice() == "--" {
let mut j = i + 1;
while j < l { free.push(args[j].clone()); j += 1; }
break;
} else {
let mut names;
let mut i_arg = None;
if cur[1] == '-' as u8 {
let tail = cur.slice(2, curlen);
if cur.as_slice()[1] == '-' as u8 {
let tail = cur.as_slice().slice(2, curlen);
let tail_eq: Vec<&str> = tail.split('=').collect();
if tail_eq.len() <= 1 {
names = vec!(Long(tail.to_owned()));
names = vec!(Long(tail.to_strbuf()));
} else {
names =
vec!(Long((*tail_eq.get(0)).to_owned()));
i_arg = Some((*tail_eq.get(1)).to_owned());
vec!(Long((*tail_eq.get(0)).to_strbuf()));
i_arg = Some((*tail_eq.get(1)).to_strbuf());
}
} else {
let mut j = 1;
let mut last_valid_opt_id = None;
names = Vec::new();
while j < curlen {
let range = cur.char_range_at(j);
let range = cur.as_slice().char_range_at(j);
let opt = Short(range.ch);
/* In a series of potential options (eg. -aheJ), if we
......@@ -576,7 +581,8 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result {
No => false
};
if arg_follows && j < curlen {
i_arg = Some(cur.slice(j, curlen).to_owned());
i_arg = Some(cur.as_slice()
.slice(j, curlen).to_strbuf());
break;
} else {
last_valid_opt_id = None;
......@@ -606,8 +612,8 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result {
vals.get_mut(optid)
.push(Val((i_arg.clone())
.unwrap()));
} else if name_pos < names.len() ||
i + 1 == l || is_arg(args[i + 1]) {
} else if name_pos < names.len() || i + 1 == l ||
is_arg(args[i + 1].as_slice()) {
vals.get_mut(optid).push(Given);
} else {
i += 1;
......@@ -653,7 +659,7 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result {
}
/// Derive a usage message from a set of long options.
pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
pub fn usage(brief: &str, opts: &[OptGroup]) -> StrBuf {
let desc_sep = "\n" + " ".repeat(24);
......@@ -672,7 +678,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
0 => {}
1 => {
row.push_char('-');
row.push_str(short_name);
row.push_str(short_name.as_slice());
row.push_char(' ');
}
_ => fail!("the short name should only be 1 ascii char long"),
......@@ -683,7 +689,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
0 => {}
_ => {
row.push_str("--");
row.push_str(long_name);
row.push_str(long_name.as_slice());
row.push_char(' ');
}
}
......@@ -691,10 +697,10 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
// arg
match hasarg {
No => {}
Yes => row.push_str(hint),
Yes => row.push_str(hint.as_slice()),
Maybe => {
row.push_char('[');
row.push_str(hint);
row.push_str(hint.as_slice());
row.push_char(']');
}
}
......@@ -712,7 +718,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
// Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = StrBuf::new();
for word in desc.words() {
for word in desc.as_slice().words() {
desc_normalized_whitespace.push_str(word);
desc_normalized_whitespace.push_char(' ');
}
......@@ -730,13 +736,15 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
// wrapped description
row.push_str(desc_rows.connect(desc_sep));
row.into_owned()
row
});
format!("{}\n\nOptions:\n{}\n", brief, rows.collect::<Vec<~str> >().connect("\n"))
format_strbuf!("{}\n\nOptions:\n{}\n",
brief,
rows.collect::<Vec<StrBuf>>().connect("\n"))
}
fn format_option(opt: &OptGroup) -> ~str {
fn format_option(opt: &OptGroup) -> StrBuf {
let mut line = StrBuf::new();
if opt.occur != Req {
......@@ -746,10 +754,10 @@ fn format_option(opt: &OptGroup) -> ~str {
// Use short_name is possible, but fallback to long_name.
if opt.short_name.len() > 0 {
line.push_char('-');
line.push_str(opt.short_name);
line.push_str(opt.short_name.as_slice());
} else {
line.push_str("--");
line.push_str(opt.long_name);
line.push_str(opt.long_name.as_slice());
}
if opt.hasarg != No {
......@@ -757,7 +765,7 @@ fn format_option(opt: &OptGroup) -> ~str {
if opt.hasarg == Maybe {
line.push_char('[');
}
line.push_str(opt.hint);
line.push_str(opt.hint.as_slice());
if opt.hasarg == Maybe {
line.push_char(']');
}
......@@ -770,14 +778,14 @@ fn format_option(opt: &OptGroup) -> ~str {
line.push_str("..");
}
line.into_owned()
line
}
/// Derive a short one-line usage summary from a set of long options.
pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> ~str {
let mut line = StrBuf::from_str("Usage: " + program_name + " ");
line.push_str(opts.iter().map(format_option).collect::<Vec<~str>>().connect(" "));
line.into_owned()
pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> StrBuf {
let mut line = format_strbuf!("Usage: {} ", program_name);
line.push_str(opts.iter().map(format_option).collect::<Vec<StrBuf>>().connect(" "));
line
}
......@@ -886,18 +894,21 @@ enum LengthLimit {
#[test]
fn test_split_within() {
fn t(s: &str, i: uint, u: &[~str]) {
fn t(s: &str, i: uint, u: &[StrBuf]) {
let mut v = Vec::new();
each_split_within(s, i, |s| { v.push(s.to_owned()); true });
each_split_within(s, i, |s| { v.push(s.to_strbuf()); true });
assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
}
t("", 0, []);
t("", 15, []);
t("hello", 15, ["hello".to_owned()]);
t("\nMary had a little lamb\nLittle lamb\n", 15,
["Mary had a".to_owned(), "little lamb".to_owned(), "Little lamb".to_owned()]);
t("hello", 15, ["hello".to_strbuf()]);
t("\nMary had a little lamb\nLittle lamb\n", 15, [
"Mary had a".to_strbuf(),
"little lamb".to_strbuf(),
"Little lamb".to_strbuf()
]);
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::MAX,
["Mary had a little lamb\nLittle lamb".to_owned()]);
["Mary had a little lamb\nLittle lamb".to_strbuf()]);
}
#[cfg(test)]
......@@ -920,25 +931,25 @@ fn check_fail_type(f: Fail_, ft: FailType) {
// Tests for reqopt
#[test]
fn test_reqopt() {
let long_args = vec!("--test=20".to_owned());
let long_args = vec!("--test=20".to_strbuf());
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!(m.opt_present("t"));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => { fail!("test_reqopt failed (long arg)"); }
}
let short_args = vec!("-t".to_owned(), "20".to_owned());
let short_args = vec!("-t".to_strbuf(), "20".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => {
assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => { fail!("test_reqopt failed (short arg)"); }
}
......@@ -946,7 +957,7 @@ fn test_reqopt() {
#[test]
fn test_reqopt_missing() {
let args = vec!("blah".to_owned());
let args = vec!("blah".to_strbuf());
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -957,14 +968,14 @@ fn test_reqopt_missing() {
#[test]
fn test_reqopt_no_arg() {
let long_args = vec!("--test".to_owned());
let long_args = vec!("--test".to_strbuf());
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
let short_args = vec!("-t".to_owned());
let short_args = vec!("-t".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
......@@ -973,7 +984,7 @@ fn test_reqopt_no_arg() {
#[test]
fn test_reqopt_multi() {
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
let args = vec!("--test=20".to_strbuf(), "-t".to_strbuf(), "30".to_strbuf());
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -985,25 +996,25 @@ fn test_reqopt_multi() {
// Tests for optopt
#[test]
fn test_optopt() {
let long_args = vec!("--test=20".to_owned());
let long_args = vec!("--test=20".to_strbuf());
let opts = vec!(optopt("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => fail!()
}
let short_args = vec!("-t".to_owned(), "20".to_owned());
let short_args = vec!("-t".to_strbuf(), "20".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => {
assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => fail!()
}
......@@ -1011,7 +1022,7 @@ fn test_optopt() {
#[test]
fn test_optopt_missing() {
let args = vec!("blah".to_owned());
let args = vec!("blah".to_strbuf());
let opts = vec!(optopt("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1025,14 +1036,14 @@ fn test_optopt_missing() {
#[test]
fn test_optopt_no_arg() {
let long_args = vec!("--test".to_owned());
let long_args = vec!("--test".to_strbuf());
let opts = vec!(optopt("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
let short_args = vec!("-t".to_owned());
let short_args = vec!("-t".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
......@@ -1041,7 +1052,7 @@ fn test_optopt_no_arg() {
#[test]
fn test_optopt_multi() {
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
let args = vec!("--test=20".to_strbuf(), "-t".to_strbuf(), "30".to_strbuf());
let opts = vec!(optopt("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1053,7 +1064,7 @@ fn test_optopt_multi() {
// Tests for optflag
#[test]
fn test_optflag() {
let long_args = vec!("--test".to_owned());
let long_args = vec!("--test".to_strbuf());
let opts = vec!(optflag("t", "test", "testing"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
......@@ -1063,7 +1074,7 @@ fn test_optflag() {
}
_ => fail!()
}
let short_args = vec!("-t".to_owned());
let short_args = vec!("-t".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => {
assert!(m.opt_present("test"));
......@@ -1075,7 +1086,7 @@ fn test_optflag() {
#[test]
fn test_optflag_missing() {
let args = vec!("blah".to_owned());
let args = vec!("blah".to_strbuf());
let opts = vec!(optflag("t", "test", "testing"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1089,7 +1100,7 @@ fn test_optflag_missing() {
#[test]
fn test_optflag_long_arg() {
let args = vec!("--test=20".to_owned());
let args = vec!("--test=20".to_strbuf());
let opts = vec!(optflag("t", "test", "testing"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1103,7 +1114,7 @@ fn test_optflag_long_arg() {
#[test]
fn test_optflag_multi() {
let args = vec!("--test".to_owned(), "-t".to_owned());
let args = vec!("--test".to_strbuf(), "-t".to_strbuf());
let opts = vec!(optflag("t", "test", "testing"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1114,14 +1125,14 @@ fn test_optflag_multi() {
#[test]
fn test_optflag_short_arg() {
let args = vec!("-t".to_owned(), "20".to_owned());
let args = vec!("-t".to_strbuf(), "20".to_strbuf());
let opts = vec!(optflag("t", "test", "testing"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
// The next variable after the flag is just a free argument
assert!(*m.free.get(0) == "20".to_owned());
assert!(*m.free.get(0) == "20".to_strbuf());
}
_ => fail!()
}
......@@ -1130,7 +1141,7 @@ fn test_optflag_short_arg() {
// Tests for optflagmulti
#[test]
fn test_optflagmulti_short1() {
let args = vec!("-v".to_owned());
let args = vec!("-v".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1143,7 +1154,7 @@ fn test_optflagmulti_short1() {
#[test]
fn test_optflagmulti_short2a() {
let args = vec!("-v".to_owned(), "-v".to_owned());
let args = vec!("-v".to_strbuf(), "-v".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1156,7 +1167,7 @@ fn test_optflagmulti_short2a() {
#[test]
fn test_optflagmulti_short2b() {
let args = vec!("-vv".to_owned());
let args = vec!("-vv".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1169,7 +1180,7 @@ fn test_optflagmulti_short2b() {
#[test]
fn test_optflagmulti_long1() {
let args = vec!("--verbose".to_owned());
let args = vec!("--verbose".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1182,7 +1193,7 @@ fn test_optflagmulti_long1() {
#[test]
fn test_optflagmulti_long2() {
let args = vec!("--verbose".to_owned(), "--verbose".to_owned());
let args = vec!("--verbose".to_strbuf(), "--verbose".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1195,8 +1206,8 @@ fn test_optflagmulti_long2() {
#[test]
fn test_optflagmulti_mix() {
let args = vec!("--verbose".to_owned(), "-v".to_owned(),
"-vv".to_owned(), "verbose".to_owned());
let args = vec!("--verbose".to_strbuf(), "-v".to_strbuf(),
"-vv".to_strbuf(), "verbose".to_strbuf());
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1211,25 +1222,25 @@ fn test_optflagmulti_mix() {
// Tests for optmulti
#[test]
fn test_optmulti() {
let long_args = vec!("--test=20".to_owned());
let long_args = vec!("--test=20".to_strbuf());
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => fail!()
}
let short_args = vec!("-t".to_owned(), "20".to_owned());
let short_args = vec!("-t".to_strbuf(), "20".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Ok(ref m) => {
assert!((m.opt_present("test")));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!((m.opt_present("t")));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
}
_ => fail!()
}
......@@ -1237,7 +1248,7 @@ fn test_optmulti() {
#[test]
fn test_optmulti_missing() {
let args = vec!("blah".to_owned());
let args = vec!("blah".to_strbuf());
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
......@@ -1251,14 +1262,14 @@ fn test_optmulti_missing() {
#[test]
fn test_optmulti_no_arg() {
let long_args = vec!("--test".to_owned());
let long_args = vec!("--test".to_strbuf());
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
let short_args = vec!("-t".to_owned());
let short_args = vec!("-t".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
......@@ -1267,18 +1278,18 @@ fn test_optmulti_no_arg() {
#[test]
fn test_optmulti_multi() {
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
let args = vec!("--test=20".to_strbuf(), "-t".to_strbuf(), "30".to_strbuf());
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
assert!(m.opt_present("test"));
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("test").unwrap(), "20".to_strbuf());
assert!(m.opt_present("t"));
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
assert_eq!(m.opt_str("t").unwrap(), "20".to_strbuf());
let pair = m.opt_strs("test");
assert!(*pair.get(0) == "20".to_owned());
assert!(*pair.get(1) == "30".to_owned());
assert!(*pair.get(0) == "20".to_strbuf());
assert!(*pair.get(1) == "30".to_strbuf());
}
_ => fail!()
}
......@@ -1286,14 +1297,14 @@ fn test_optmulti_multi() {
#[test]
fn test_unrecognized_option() {
let long_args = vec!("--untest".to_owned());
let long_args = vec!("--untest".to_strbuf());
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
let rs = getopts(long_args.as_slice(), opts.as_slice());
match rs {
Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!()
}
let short_args = vec!("-u".to_owned());
let short_args = vec!("-u".to_strbuf());
match getopts(short_args.as_slice(), opts.as_slice()) {
Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!()
......@@ -1303,10 +1314,22 @@ fn test_unrecognized_option() {
#[test]
fn test_combined() {
let args =
vec!("prog".to_owned(), "free1".to_owned(), "-s".to_owned(), "20".to_owned(),
"free2".to_owned(), "--flag".to_owned(), "--long=30".to_owned(), "-f".to_owned(),
"-m".to_owned(), "40".to_owned(), "-m".to_owned(), "50".to_owned(), "-n".to_owned(),
"-A B".to_owned(), "-n".to_owned(), "-60 70".to_owned());
vec!("prog".to_strbuf(),
"free1".to_strbuf(),
"-s".to_strbuf(),
"20".to_strbuf(),
"free2".to_strbuf(),
"--flag".to_strbuf(),
"--long=30".to_strbuf(),
"-f".to_strbuf(),
"-m".to_strbuf(),
"40".to_strbuf(),
"-m".to_strbuf(),
"50".to_strbuf(),
"-n".to_strbuf(),
"-A B".to_strbuf(),
"-n".to_strbuf(),
"-60 70".to_strbuf());
let opts =
vec!(optopt("s", "something", "something", "SOMETHING"),
optflag("", "flag", "a flag"),
......@@ -1318,19 +1341,19 @@ fn test_combined() {
let rs = getopts(args.as_slice(), opts.as_slice());
match rs {
Ok(ref m) => {
assert!(*m.free.get(0) == "prog".to_owned());
assert!(*m.free.get(1) == "free1".to_owned());
assert_eq!(m.opt_str("s").unwrap(), "20".to_owned());
assert!(*m.free.get(2) == "free2".to_owned());
assert!(*m.free.get(0) == "prog".to_strbuf());
assert!(*m.free.get(1) == "free1".to_strbuf());
assert_eq!(m.opt_str("s").unwrap(), "20".to_strbuf());
assert!(*m.free.get(2) == "free2".to_strbuf());
assert!((m.opt_present("flag")));
assert_eq!(m.opt_str("long").unwrap(), "30".to_owned());
assert_eq!(m.opt_str("long").unwrap(), "30".to_strbuf());
assert!((m.opt_present("f")));
let pair = m.opt_strs("m");
assert!(*pair.get(0) == "40".to_owned());
assert!(*pair.get(1) == "50".to_owned());
assert!(*pair.get(0) == "40".to_strbuf());
assert!(*pair.get(1) == "50".to_strbuf());
let pair = m.opt_strs("n");
assert!(*pair.get(0) == "-A B".to_owned());
assert!(*pair.get(1) == "-60 70".to_owned());
assert!(*pair.get(0) == "-A B".to_strbuf());
assert!(*pair.get(1) == "-60 70".to_strbuf());
assert!((!m.opt_present("notpresent")));
}
_ => fail!()
......@@ -1343,68 +1366,68 @@ fn test_multi() {
optopt("", "encrypt", "encrypt", "ENCRYPT"),
optopt("f", "", "flag", "FLAG"));
let args_single = vec!("-e".to_owned(), "foo".to_owned());
let args_single = vec!("-e".to_strbuf(), "foo".to_strbuf());
let matches_single = &match getopts(args_single.as_slice(),
opts.as_slice()) {
result::Ok(m) => m,
result::Err(_) => fail!()
};
assert!(matches_single.opts_present(["e".to_owned()]));
assert!(matches_single.opts_present(["encrypt".to_owned(), "e".to_owned()]));
assert!(matches_single.opts_present(["e".to_owned(), "encrypt".to_owned()]));
assert!(!matches_single.opts_present(["encrypt".to_owned()]));
assert!(!matches_single.opts_present(["thing".to_owned()]));
assert!(matches_single.opts_present(["e".to_strbuf()]));
assert!(matches_single.opts_present(["encrypt".to_strbuf(), "e".to_strbuf()]));
assert!(matches_single.opts_present(["e".to_strbuf(), "encrypt".to_strbuf()]));
assert!(!matches_single.opts_present(["encrypt".to_strbuf()]));
assert!(!matches_single.opts_present(["thing".to_strbuf()]));
assert!(!matches_single.opts_present([]));
assert_eq!(matches_single.opts_str(["e".to_owned()]).unwrap(), "foo".to_owned());
assert_eq!(matches_single.opts_str(["e".to_owned(), "encrypt".to_owned()]).unwrap(),
"foo".to_owned());
assert_eq!(matches_single.opts_str(["encrypt".to_owned(), "e".to_owned()]).unwrap(),
"foo".to_owned());
assert_eq!(matches_single.opts_str(["e".to_strbuf()]).unwrap(), "foo".to_strbuf());
assert_eq!(matches_single.opts_str(["e".to_strbuf(), "encrypt".to_strbuf()]).unwrap(),
"foo".to_strbuf());
assert_eq!(matches_single.opts_str(["encrypt".to_strbuf(), "e".to_strbuf()]).unwrap(),
"foo".to_strbuf());
let args_both = vec!("-e".to_owned(), "foo".to_owned(), "--encrypt".to_owned(),
"foo".to_owned());
let args_both = vec!("-e".to_strbuf(), "foo".to_strbuf(), "--encrypt".to_strbuf(),
"foo".to_strbuf());
let matches_both = &match getopts(args_both.as_slice(),
opts.as_slice()) {
result::Ok(m) => m,
result::Err(_) => fail!()
};
assert!(matches_both.opts_present(["e".to_owned()]));
assert!(matches_both.opts_present(["encrypt".to_owned()]));
assert!(matches_both.opts_present(["encrypt".to_owned(), "e".to_owned()]));
assert!(matches_both.opts_present(["e".to_owned(), "encrypt".to_owned()]));
assert!(!matches_both.opts_present(["f".to_owned()]));
assert!(!matches_both.opts_present(["thing".to_owned()]));
assert!(matches_both.opts_present(["e".to_strbuf()]));
assert!(matches_both.opts_present(["encrypt".to_strbuf()]));
assert!(matches_both.opts_present(["encrypt".to_strbuf(), "e".to_strbuf()]));
assert!(matches_both.opts_present(["e".to_strbuf(), "encrypt".to_strbuf()]));
assert!(!matches_both.opts_present(["f".to_strbuf()]));
assert!(!matches_both.opts_present(["thing".to_strbuf()]));
assert!(!matches_both.opts_present([]));
assert_eq!(matches_both.opts_str(["e".to_owned()]).unwrap(), "foo".to_owned());
assert_eq!(matches_both.opts_str(["encrypt".to_owned()]).unwrap(), "foo".to_owned());
assert_eq!(matches_both.opts_str(["e".to_owned(), "encrypt".to_owned()]).unwrap(),
"foo".to_owned());
assert_eq!(matches_both.opts_str(["encrypt".to_owned(), "e".to_owned()]).unwrap(),
"foo".to_owned());
assert_eq!(matches_both.opts_str(["e".to_strbuf()]).unwrap(), "foo".to_strbuf());
assert_eq!(matches_both.opts_str(["encrypt".to_strbuf()]).unwrap(), "foo".to_strbuf());
assert_eq!(matches_both.opts_str(["e".to_strbuf(), "encrypt".to_strbuf()]).unwrap(),
"foo".to_strbuf());
assert_eq!(matches_both.opts_str(["encrypt".to_strbuf(), "e".to_strbuf()]).unwrap(),
"foo".to_strbuf());
}
#[test]
fn test_nospace() {
let args = vec!("-Lfoo".to_owned(), "-M.".to_owned());
let args = vec!("-Lfoo".to_strbuf(), "-M.".to_strbuf());
let opts = vec!(optmulti("L", "", "library directory", "LIB"),
optmulti("M", "", "something", "MMMM"));
let matches = &match getopts(args.as_slice(), opts.as_slice()) {
result::Ok(m) => m,
result::Err(_) => fail!()
};
assert!(matches.opts_present(["L".to_owned()]));
assert_eq!(matches.opts_str(["L".to_owned()]).unwrap(), "foo".to_owned());
assert!(matches.opts_present(["M".to_owned()]));
assert_eq!(matches.opts_str(["M".to_owned()]).unwrap(), ".".to_owned());
assert!(matches.opts_present(["L".to_strbuf()]));
assert_eq!(matches.opts_str(["L".to_strbuf()]).unwrap(), "foo".to_strbuf());
assert!(matches.opts_present(["M".to_strbuf()]));
assert_eq!(matches.opts_str(["M".to_strbuf()]).unwrap(), ".".to_strbuf());
}
#[test]
fn test_long_to_short() {
let mut short = Opt {
name: Long("banana".to_owned()),
name: Long("banana".to_strbuf()),
hasarg: Yes,
occur: Req,
aliases: Vec::new(),
......@@ -1423,7 +1446,7 @@ fn test_aliases_long_and_short() {
let opts = vec!(
optflagmulti("a", "apple", "Desc"));
let args = vec!("-a".to_owned(), "--apple".to_owned(), "-a".to_owned());
let args = vec!("-a".to_strbuf(), "--apple".to_strbuf(), "-a".to_strbuf());
let matches = getopts(args.as_slice(), opts.as_slice()).unwrap();
assert_eq!(3, matches.opt_count("a"));
......@@ -1450,7 +1473,7 @@ fn test_usage() {
-k --kiwi Desc
-p [VAL] Desc
-l VAL Desc
".to_owned();
".to_strbuf();
let generated_usage = usage("Usage: fruits", optgroups.as_slice());
......@@ -1477,7 +1500,7 @@ fn test_usage_description_wrapping() {
-k --kiwi This is a long description which won't be wrapped..+..
-a --apple This is a long description which _will_ be
wrapped..+..
".to_owned();
".to_strbuf();
let usage = usage("Usage: fruits", optgroups.as_slice());
......@@ -1503,7 +1526,7 @@ fn test_usage_description_multibyte_handling() {
-a --apple This “description” has some characters that could
confuse the line wrapping; an apple costs 0.51€ in
some parts of Europe.
".to_owned();
".to_strbuf();
let usage = usage("Usage: fruits", optgroups.as_slice());
......@@ -1522,7 +1545,7 @@ fn test_short_usage() {
optflagopt("p", "", "Desc", "VAL"),
optmulti("l", "", "Desc", "VAL"));
let expected = "Usage: fruits -b VAL [-a VAL] [-k] [-p [VAL]] [-l VAL]..".to_owned();
let expected = "Usage: fruits -b VAL [-a VAL] [-k] [-p [VAL]] [-l VAL]..".to_strbuf();
let generated_usage = short_usage("fruits", optgroups.as_slice());
debug!("expected: <<{}>>", expected);
......
......@@ -319,7 +319,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
{
let mut cg = basic_codegen_options();
for option in matches.opt_strs("C").move_iter() {
let mut iter = option.splitn('=', 1);
let mut iter = option.as_slice().splitn('=', 1);
let key = iter.next().unwrap();
let value = iter.next();
let option_to_lookup = key.replace("-", "_");
......@@ -563,7 +563,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut crate_types: Vec<CrateType> = Vec::new();
let unparsed_crate_types = matches.opt_strs("crate-type");
for unparsed_crate_type in unparsed_crate_types.iter() {
for part in unparsed_crate_type.split(',') {
for part in unparsed_crate_type.as_slice().split(',') {
let new_part = match part {
"lib" => default_lib_output(),
"rlib" => CrateTypeRlib,
......@@ -612,7 +612,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut this_bit = 0;
for tuple in debug_map.iter() {
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
if *name == *debug_flag { this_bit = bit; break; }
if *name == debug_flag.as_slice() {
this_bit = bit;
break;
}
}
if this_bit == 0 {
early_error(format!("unknown debug flag: {}", *debug_flag))
......@@ -628,7 +631,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
if !parse_only && !no_trans {
let unparsed_output_types = matches.opt_strs("emit");
for unparsed_output_type in unparsed_output_types.iter() {
for part in unparsed_output_type.split(',') {
for part in unparsed_output_type.as_slice().split(',') {
let output_type = match part.as_slice() {
"asm" => link::OutputTypeAssembly,
"ir" => link::OutputTypeLlvmAssembly,
......@@ -765,7 +768,7 @@ mod test {
#[test]
fn test_switch_implies_cfg_test() {
let matches =
&match getopts(["--test".to_owned()], optgroups().as_slice()) {
&match getopts(["--test".to_strbuf()], optgroups().as_slice()) {
Ok(m) => m,
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
};
......@@ -780,7 +783,7 @@ fn test_switch_implies_cfg_test() {
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches =
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()],
&match getopts(["--test".to_strbuf(), "--cfg=test".to_strbuf()],
optgroups().as_slice()) {
Ok(m) => m,
Err(f) => {
......
......@@ -35,7 +35,7 @@
pub mod config;
pub fn main_args(args: &[~str]) -> int {
pub fn main_args(args: &[StrBuf]) -> int {
let owned_args = args.to_owned();
monitor(proc() run_compiler(owned_args));
0
......@@ -44,7 +44,7 @@ pub fn main_args(args: &[~str]) -> int {
static BUG_REPORT_URL: &'static str =
"http://static.rust-lang.org/doc/master/complement-bugreport.html";
fn run_compiler(args: &[~str]) {
fn run_compiler(args: &[StrBuf]) {
let matches = match handle_options(Vec::from_slice(args)) {
Some(matches) => matches,
None => return
......@@ -73,7 +73,7 @@ fn run_compiler(args: &[~str]) {
let ofile = matches.opt_str("o").map(|o| Path::new(o));
let pretty = matches.opt_default("pretty", "normal").map(|a| {
parse_pretty(&sess, a)
parse_pretty(&sess, a.as_slice())
});
match pretty {
Some::<PpMode>(ppm) => {
......@@ -84,7 +84,7 @@ fn run_compiler(args: &[~str]) {
}
let r = matches.opt_strs("Z");
if r.contains(&("ls".to_owned())) {
if r.contains(&("ls".to_strbuf())) {
match input {
FileInput(ref ifile) => {
let mut stdout = io::stdout();
......@@ -191,17 +191,20 @@ fn describe_codegen_flags() {
/// Process command line options. Emits messages as appropirate.If compilation
/// should continue, returns a getopts::Matches object parsed from args, otherwise
/// returns None.
pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> {
pub fn handle_options(mut args: Vec<StrBuf>) -> Option<getopts::Matches> {
// Throw away the first argument, the name of the binary
let _binary = args.shift().unwrap();
if args.is_empty() { usage(); return None; }
if args.is_empty() {
usage();
return None;
}
let matches =
match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) {
Ok(m) => m,
Err(f) => {
early_error(f.to_err_msg());
early_error(f.to_err_msg().as_slice());
}
};
......@@ -212,24 +215,24 @@ pub fn handle_options(mut args: Vec<~str>) -> Option<getopts::Matches> {
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
matches.opt_strs("warn").as_slice());
if lint_flags.iter().any(|x| x == &"help".to_owned()) {
if lint_flags.iter().any(|x| x.as_slice() == "help") {
describe_warnings();
return None;
}
let r = matches.opt_strs("Z");
if r.iter().any(|x| x == &"help".to_owned()) {
if r.iter().any(|x| x.as_slice() == "help") {
describe_debug_flags();
return None;
}
let cg_flags = matches.opt_strs("C");
if cg_flags.iter().any(|x| x == &"help".to_owned()) {
if cg_flags.iter().any(|x| x.as_slice() == "help") {
describe_codegen_flags();
return None;
}
if cg_flags.contains(&"passes=list".to_owned()) {
if cg_flags.contains(&"passes=list".to_strbuf()) {
unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); }
return None;
}
......
......@@ -121,5 +121,8 @@ pub mod lib {
}
pub fn main() {
std::os::set_exit_status(driver::main_args(std::os::args().as_slice()));
let args = std::os::args().iter()
.map(|x| x.to_strbuf())
.collect::<Vec<_>>();
std::os::set_exit_status(driver::main_args(args.as_slice()));
}
......@@ -137,12 +137,7 @@ pub fn usage(argv0: &str) {
}
pub fn main_args(args: &[StrBuf]) -> int {
let matches = match getopts::getopts(args.tail()
.iter()
.map(|x| (*x).to_owned())
.collect::<Vec<_>>()
.as_slice(),
opts().as_slice()) {
let matches = match getopts::getopts(args.tail(), opts().as_slice()) {
Ok(m) => m,
Err(err) => {
println!("{}", err.to_err_msg());
......@@ -170,7 +165,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
let test_args = matches.opt_strs("test-args");
let test_args: Vec<StrBuf> = test_args.iter()
.flat_map(|s| s.words())
.flat_map(|s| s.as_slice().words())
.map(|s| s.to_strbuf())
.collect();
......@@ -199,7 +194,7 @@ pub fn main_args(args: &[StrBuf]) -> int {
(false, false) => {}
}
if matches.opt_strs("passes").as_slice() == &["list".to_owned()] {
if matches.opt_strs("passes").as_slice() == &["list".to_strbuf()] {
println!("Available passes for running rustdoc:");
for &(name, _, description) in PASSES.iter() {
println!("{:>20s} - {}", name, description);
......@@ -306,7 +301,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
clean::NameValue(ref x, ref value)
if "passes" == x.as_slice() => {
for pass in value.as_slice().words() {
passes.push(pass.to_owned());
passes.push(pass.to_strbuf());
}
}
clean::NameValue(ref x, ref value)
......@@ -323,15 +318,19 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
}
if default_passes {
for name in DEFAULT_PASSES.iter().rev() {
passes.unshift(name.to_owned());
passes.unshift(name.to_strbuf());
}
}
// Load all plugins/passes into a PluginManager
let path = matches.opt_str("plugin-path").unwrap_or("/tmp/rustdoc/plugins".to_owned());
let path = matches.opt_str("plugin-path")
.unwrap_or("/tmp/rustdoc/plugins".to_strbuf());
let mut pm = plugins::PluginManager::new(Path::new(path));
for pass in passes.iter() {
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) {
let plugin = match PASSES.iter()
.position(|&(p, _, _)| {
p == pass.as_slice()
}) {
Some(i) => PASSES[i].val1(),
None => {
error!("unknown pass {}, skipping", *pass);
......
......@@ -354,11 +354,7 @@ fn usage(binary: &str) {
pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
let args_ = args.tail();
let matches =
match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
optgroups().as_slice()) {
match getopts::getopts(args_.as_slice(), optgroups().as_slice()) {
Ok(m) => m,
Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
};
......@@ -388,7 +384,8 @@ pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s));
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());
let ratchet_noise_percent =
ratchet_noise_percent.map(|s| from_str::<f64>(s.as_slice()).unwrap());
let save_metrics = matches.opt_str("save-metrics");
let save_metrics = save_metrics.map(|s| Path::new(s));
......
......@@ -55,7 +55,7 @@ struct Config {
fn parse_opts(argv: Vec<StrBuf> ) -> Config {
let opts = vec!(getopts::optflag("", "stress", ""));
let argv = argv.iter().map(|x| x.to_str()).collect::<Vec<_>>();
let argv = argv.iter().map(|x| x.to_strbuf()).collect::<Vec<_>>();
let opt_args = argv.slice(1, argv.len());
match getopts::getopts(opt_args, opts.as_slice()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册