Skip to content

Commit 654b4d6

Browse files
committed
De-export std::{json, getopts}. Part of #3583.
1 parent fb83b40 commit 654b4d6

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

src/libstd/getopts.rs

+18-36
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,6 @@ use core::cmp::Eq;
6868
use core::result::{Err, Ok};
6969
use core::option;
7070
use core::option::{Some, None};
71-
export Opt;
72-
export reqopt;
73-
export optopt;
74-
export optflag;
75-
export optflagopt;
76-
export optmulti;
77-
export getopts;
78-
export Matches;
79-
export Fail_;
80-
export fail_str;
81-
export opt_present;
82-
export opts_present;
83-
export opt_str;
84-
export opts_str;
85-
export opt_strs;
86-
export opt_maybe_str;
87-
export opt_default;
88-
export Result; //NDM
8971

9072
enum Name {
9173
Long(~str),
@@ -97,7 +79,7 @@ enum HasArg { Yes, No, Maybe, }
9779
enum Occur { Req, Optional, Multi, }
9880

9981
/// A description of a possible option
100-
type Opt = {name: Name, hasarg: HasArg, occur: Occur};
82+
pub type Opt = {name: Name, hasarg: HasArg, occur: Occur};
10183

10284
fn mkname(nm: &str) -> Name {
10385
let unm = str::from_slice(nm);
@@ -134,30 +116,30 @@ impl Occur : Eq {
134116
}
135117

136118
/// Create an option that is required and takes an argument
137-
fn reqopt(name: &str) -> Opt {
119+
pub fn reqopt(name: &str) -> Opt {
138120
return {name: mkname(name), hasarg: Yes, occur: Req};
139121
}
140122

141123
/// Create an option that is optional and takes an argument
142-
fn optopt(name: &str) -> Opt {
124+
pub fn optopt(name: &str) -> Opt {
143125
return {name: mkname(name), hasarg: Yes, occur: Optional};
144126
}
145127

146128
/// Create an option that is optional and does not take an argument
147-
fn optflag(name: &str) -> Opt {
129+
pub fn optflag(name: &str) -> Opt {
148130
return {name: mkname(name), hasarg: No, occur: Optional};
149131
}
150132

151133
/// Create an option that is optional and takes an optional argument
152-
fn optflagopt(name: &str) -> Opt {
134+
pub fn optflagopt(name: &str) -> Opt {
153135
return {name: mkname(name), hasarg: Maybe, occur: Optional};
154136
}
155137

156138
/**
157139
* Create an option that is optional, takes an argument, and may occur
158140
* multiple times
159141
*/
160-
fn optmulti(name: &str) -> Opt {
142+
pub fn optmulti(name: &str) -> Opt {
161143
return {name: mkname(name), hasarg: Yes, occur: Multi};
162144
}
163145

@@ -167,7 +149,7 @@ enum Optval { Val(~str), Given, }
167149
* The result of checking command line arguments. Contains a vector
168150
* of matches and a vector of free strings.
169151
*/
170-
type Matches = {opts: ~[Opt], vals: ~[~[Optval]], free: ~[~str]};
152+
pub type Matches = {opts: ~[Opt], vals: ~[~[Optval]], free: ~[~str]};
171153

172154
fn is_arg(arg: &str) -> bool {
173155
return str::len(arg) > 1u && arg[0] == '-' as u8;
@@ -188,7 +170,7 @@ fn find_opt(opts: &[Opt], +nm: Name) -> Option<uint> {
188170
* The type returned when the command line does not conform to the
189171
* expected format. Pass this value to <fail_str> to get an error message.
190172
*/
191-
enum Fail_ {
173+
pub enum Fail_ {
192174
ArgumentMissing(~str),
193175
UnrecognizedOption(~str),
194176
OptionMissing(~str),
@@ -197,7 +179,7 @@ enum Fail_ {
197179
}
198180

199181
/// Convert a `fail_` enum into an error string
200-
fn fail_str(+f: Fail_) -> ~str {
182+
pub fn fail_str(+f: Fail_) -> ~str {
201183
return match f {
202184
ArgumentMissing(ref nm) => {
203185
~"Argument to option '" + *nm + ~"' missing."
@@ -221,7 +203,7 @@ fn fail_str(+f: Fail_) -> ~str {
221203
* The result of parsing a command line with a set of options
222204
* (result::t<Matches, Fail_>)
223205
*/
224-
type Result = result::Result<Matches, Fail_>;
206+
pub type Result = result::Result<Matches, Fail_>;
225207

226208
/**
227209
* Parse command line arguments according to the provided options
@@ -230,7 +212,7 @@ type Result = result::Result<Matches, Fail_>;
230212
* `opt_str`, etc. to interrogate results. Returns `err(Fail_)` on failure.
231213
* Use <fail_str> to get an error message.
232214
*/
233-
fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
215+
pub fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe {
234216
let n_opts = vec::len::<Opt>(opts);
235217
fn f(+_x: uint) -> ~[Optval] { return ~[]; }
236218
let vals = vec::to_mut(vec::from_fn(n_opts, f));
@@ -366,12 +348,12 @@ fn opt_vals(+mm: Matches, nm: &str) -> ~[Optval] {
366348
fn opt_val(+mm: Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; }
367349

368350
/// Returns true if an option was matched
369-
fn opt_present(+mm: Matches, nm: &str) -> bool {
351+
pub fn opt_present(+mm: Matches, nm: &str) -> bool {
370352
return vec::len::<Optval>(opt_vals(mm, nm)) > 0u;
371353
}
372354

373355
/// Returns true if any of several options were matched
374-
fn opts_present(+mm: Matches, names: &[~str]) -> bool {
356+
pub fn opts_present(+mm: Matches, names: &[~str]) -> bool {
375357
for vec::each(names) |nm| {
376358
match find_opt(mm.opts, mkname(*nm)) {
377359
Some(_) => return true,
@@ -388,7 +370,7 @@ fn opts_present(+mm: Matches, names: &[~str]) -> bool {
388370
* Fails if the option was not matched or if the match did not take an
389371
* argument
390372
*/
391-
fn opt_str(+mm: Matches, nm: &str) -> ~str {
373+
pub fn opt_str(+mm: Matches, nm: &str) -> ~str {
392374
return match opt_val(mm, nm) { Val(copy s) => s, _ => fail };
393375
}
394376

@@ -398,7 +380,7 @@ fn opt_str(+mm: Matches, nm: &str) -> ~str {
398380
* Fails if the no option was provided from the given list, or if the no such
399381
* option took an argument
400382
*/
401-
fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
383+
pub fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
402384
for vec::each(names) |nm| {
403385
match opt_val(mm, *nm) {
404386
Val(copy s) => return s,
@@ -415,7 +397,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
415397
*
416398
* Used when an option accepts multiple values.
417399
*/
418-
fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
400+
pub fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
419401
let mut acc: ~[~str] = ~[];
420402
for vec::each(opt_vals(mm, nm)) |v| {
421403
match *v { Val(copy s) => acc.push(s), _ => () }
@@ -424,7 +406,7 @@ fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
424406
}
425407

426408
/// Returns the string argument supplied to a matching option or none
427-
fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> {
409+
pub fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> {
428410
let vals = opt_vals(mm, nm);
429411
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
430412
return match vals[0] {
@@ -441,7 +423,7 @@ fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> {
441423
* present but no argument was provided, and the argument if the option was
442424
* present and an argument was provided.
443425
*/
444-
fn opt_default(+mm: Matches, nm: &str, def: &str) -> Option<~str> {
426+
pub fn opt_default(+mm: Matches, nm: &str, def: &str) -> Option<~str> {
445427
let vals = opt_vals(mm, nm);
446428
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
447429
return match vals[0] { Val(copy s) => Some::<~str>(s),

src/libstd/std.rc

-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ mod treemap;
9292
mod ebml;
9393
mod ebml2;
9494
mod dbg;
95-
#[legacy_exports]
9695
mod getopts;
97-
#[legacy_exports]
9896
mod json;
9997
mod sha1;
10098
mod md4;

0 commit comments

Comments
 (0)