diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 67bbff7fb6a3..9d127f5db476 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -68,24 +68,6 @@ use core::cmp::Eq; use core::result::{Err, Ok}; use core::option; use core::option::{Some, None}; -export Opt; -export reqopt; -export optopt; -export optflag; -export optflagopt; -export optmulti; -export getopts; -export Matches; -export Fail_; -export fail_str; -export opt_present; -export opts_present; -export opt_str; -export opts_str; -export opt_strs; -export opt_maybe_str; -export opt_default; -export Result; //NDM enum Name { Long(~str), @@ -97,7 +79,7 @@ enum HasArg { Yes, No, Maybe, } enum Occur { Req, Optional, Multi, } /// A description of a possible option -type Opt = {name: Name, hasarg: HasArg, occur: Occur}; +pub type Opt = {name: Name, hasarg: HasArg, occur: Occur}; fn mkname(nm: &str) -> Name { let unm = str::from_slice(nm); @@ -134,22 +116,22 @@ impl Occur : Eq { } /// Create an option that is required and takes an argument -fn reqopt(name: &str) -> Opt { +pub fn reqopt(name: &str) -> Opt { return {name: mkname(name), hasarg: Yes, occur: Req}; } /// Create an option that is optional and takes an argument -fn optopt(name: &str) -> Opt { +pub fn optopt(name: &str) -> Opt { return {name: mkname(name), hasarg: Yes, occur: Optional}; } /// Create an option that is optional and does not take an argument -fn optflag(name: &str) -> Opt { +pub fn optflag(name: &str) -> Opt { return {name: mkname(name), hasarg: No, occur: Optional}; } /// Create an option that is optional and takes an optional argument -fn optflagopt(name: &str) -> Opt { +pub fn optflagopt(name: &str) -> Opt { return {name: mkname(name), hasarg: Maybe, occur: Optional}; } @@ -157,7 +139,7 @@ fn optflagopt(name: &str) -> Opt { * Create an option that is optional, takes an argument, and may occur * multiple times */ -fn optmulti(name: &str) -> Opt { +pub fn optmulti(name: &str) -> Opt { return {name: mkname(name), hasarg: Yes, occur: Multi}; } @@ -167,7 +149,7 @@ enum Optval { Val(~str), Given, } * The result of checking command line arguments. Contains a vector * of matches and a vector of free strings. */ -type Matches = {opts: ~[Opt], vals: ~[~[Optval]], free: ~[~str]}; +pub type Matches = {opts: ~[Opt], vals: ~[~[Optval]], free: ~[~str]}; fn is_arg(arg: &str) -> bool { return str::len(arg) > 1u && arg[0] == '-' as u8; @@ -188,7 +170,7 @@ fn find_opt(opts: &[Opt], +nm: Name) -> Option { * The type returned when the command line does not conform to the * expected format. Pass this value to to get an error message. */ -enum Fail_ { +pub enum Fail_ { ArgumentMissing(~str), UnrecognizedOption(~str), OptionMissing(~str), @@ -197,7 +179,7 @@ enum Fail_ { } /// Convert a `fail_` enum into an error string -fn fail_str(+f: Fail_) -> ~str { +pub fn fail_str(+f: Fail_) -> ~str { return match f { ArgumentMissing(ref nm) => { ~"Argument to option '" + *nm + ~"' missing." @@ -221,7 +203,7 @@ fn fail_str(+f: Fail_) -> ~str { * The result of parsing a command line with a set of options * (result::t) */ -type Result = result::Result; +pub type Result = result::Result; /** * Parse command line arguments according to the provided options @@ -230,7 +212,7 @@ type Result = result::Result; * `opt_str`, etc. to interrogate results. Returns `err(Fail_)` on failure. * Use to get an error message. */ -fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { +pub fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { let n_opts = vec::len::(opts); fn f(+_x: uint) -> ~[Optval] { return ~[]; } let vals = vec::to_mut(vec::from_fn(n_opts, f)); @@ -366,12 +348,12 @@ fn opt_vals(+mm: Matches, nm: &str) -> ~[Optval] { fn opt_val(+mm: Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; } /// Returns true if an option was matched -fn opt_present(+mm: Matches, nm: &str) -> bool { +pub fn opt_present(+mm: Matches, nm: &str) -> bool { return vec::len::(opt_vals(mm, nm)) > 0u; } /// Returns true if any of several options were matched -fn opts_present(+mm: Matches, names: &[~str]) -> bool { +pub fn opts_present(+mm: Matches, names: &[~str]) -> bool { for vec::each(names) |nm| { match find_opt(mm.opts, mkname(*nm)) { Some(_) => return true, @@ -388,7 +370,7 @@ fn opts_present(+mm: Matches, names: &[~str]) -> bool { * Fails if the option was not matched or if the match did not take an * argument */ -fn opt_str(+mm: Matches, nm: &str) -> ~str { +pub fn opt_str(+mm: Matches, nm: &str) -> ~str { return match opt_val(mm, nm) { Val(copy s) => s, _ => fail }; } @@ -398,7 +380,7 @@ fn opt_str(+mm: Matches, nm: &str) -> ~str { * Fails if the no option was provided from the given list, or if the no such * option took an argument */ -fn opts_str(+mm: Matches, names: &[~str]) -> ~str { +pub fn opts_str(+mm: Matches, names: &[~str]) -> ~str { for vec::each(names) |nm| { match opt_val(mm, *nm) { Val(copy s) => return s, @@ -415,7 +397,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str { * * Used when an option accepts multiple values. */ -fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { +pub fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { let mut acc: ~[~str] = ~[]; for vec::each(opt_vals(mm, nm)) |v| { match *v { Val(copy s) => acc.push(s), _ => () } @@ -424,7 +406,7 @@ fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { } /// Returns the string argument supplied to a matching option or none -fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { +pub fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { @@ -441,7 +423,7 @@ fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { * present but no argument was provided, and the argument if the option was * present and an argument was provided. */ -fn opt_default(+mm: Matches, nm: &str, def: &str) -> Option<~str> { +pub fn opt_default(+mm: Matches, nm: &str, def: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { Val(copy s) => Some::<~str>(s), diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 251a492bb5b1..202cb4932db4 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -92,9 +92,7 @@ mod treemap; mod ebml; mod ebml2; mod dbg; -#[legacy_exports] mod getopts; -#[legacy_exports] mod json; mod sha1; mod md4;