@@ -68,24 +68,6 @@ use core::cmp::Eq;
68
68
use core:: result:: { Err , Ok } ;
69
69
use core:: option;
70
70
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
89
71
90
72
enum Name {
91
73
Long ( ~str ) ,
@@ -97,7 +79,7 @@ enum HasArg { Yes, No, Maybe, }
97
79
enum Occur { Req , Optional , Multi , }
98
80
99
81
/// 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 } ;
101
83
102
84
fn mkname ( nm : & str ) -> Name {
103
85
let unm = str:: from_slice ( nm) ;
@@ -134,30 +116,30 @@ impl Occur : Eq {
134
116
}
135
117
136
118
/// Create an option that is required and takes an argument
137
- fn reqopt ( name : & str ) -> Opt {
119
+ pub fn reqopt ( name : & str ) -> Opt {
138
120
return { name: mkname ( name) , hasarg: Yes , occur: Req } ;
139
121
}
140
122
141
123
/// Create an option that is optional and takes an argument
142
- fn optopt ( name : & str ) -> Opt {
124
+ pub fn optopt ( name : & str ) -> Opt {
143
125
return { name: mkname ( name) , hasarg: Yes , occur: Optional } ;
144
126
}
145
127
146
128
/// 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 {
148
130
return { name: mkname ( name) , hasarg: No , occur: Optional } ;
149
131
}
150
132
151
133
/// Create an option that is optional and takes an optional argument
152
- fn optflagopt ( name : & str ) -> Opt {
134
+ pub fn optflagopt ( name : & str ) -> Opt {
153
135
return { name: mkname ( name) , hasarg: Maybe , occur: Optional } ;
154
136
}
155
137
156
138
/**
157
139
* Create an option that is optional, takes an argument, and may occur
158
140
* multiple times
159
141
*/
160
- fn optmulti ( name : & str ) -> Opt {
142
+ pub fn optmulti ( name : & str ) -> Opt {
161
143
return { name: mkname ( name) , hasarg: Yes , occur: Multi } ;
162
144
}
163
145
@@ -167,7 +149,7 @@ enum Optval { Val(~str), Given, }
167
149
* The result of checking command line arguments. Contains a vector
168
150
* of matches and a vector of free strings.
169
151
*/
170
- type Matches = { opts : ~[ Opt ] , vals : ~[ ~[ Optval ] ] , free : ~[ ~str ] } ;
152
+ pub type Matches = { opts : ~[ Opt ] , vals : ~[ ~[ Optval ] ] , free : ~[ ~str ] } ;
171
153
172
154
fn is_arg ( arg : & str ) -> bool {
173
155
return str:: len ( arg) > 1 u && arg[ 0 ] == '-' as u8 ;
@@ -188,7 +170,7 @@ fn find_opt(opts: &[Opt], +nm: Name) -> Option<uint> {
188
170
* The type returned when the command line does not conform to the
189
171
* expected format. Pass this value to <fail_str> to get an error message.
190
172
*/
191
- enum Fail_ {
173
+ pub enum Fail_ {
192
174
ArgumentMissing ( ~str ) ,
193
175
UnrecognizedOption ( ~str ) ,
194
176
OptionMissing ( ~str ) ,
@@ -197,7 +179,7 @@ enum Fail_ {
197
179
}
198
180
199
181
/// Convert a `fail_` enum into an error string
200
- fn fail_str( +f : Fail_ ) -> ~str {
182
+ pub fn fail_str( +f : Fail_ ) -> ~str {
201
183
return match f {
202
184
ArgumentMissing ( ref nm) => {
203
185
~"Argument to option ' " + * nm + ~"' missing. "
@@ -221,7 +203,7 @@ fn fail_str(+f: Fail_) -> ~str {
221
203
* The result of parsing a command line with a set of options
222
204
* (result::t<Matches, Fail_>)
223
205
*/
224
- type Result = result:: Result < Matches , Fail_ > ;
206
+ pub type Result = result:: Result < Matches , Fail_ > ;
225
207
226
208
/**
227
209
* Parse command line arguments according to the provided options
@@ -230,7 +212,7 @@ type Result = result::Result<Matches, Fail_>;
230
212
* `opt_str`, etc. to interrogate results. Returns `err(Fail_)` on failure.
231
213
* Use <fail_str> to get an error message.
232
214
*/
233
- fn getopts( args : & [ ~str ] , opts : & [ Opt ] ) -> Result unsafe {
215
+ pub fn getopts( args : & [ ~str ] , opts : & [ Opt ] ) -> Result unsafe {
234
216
let n_opts = vec:: len :: < Opt > ( opts) ;
235
217
fn f ( +_x : uint ) -> ~[ Optval ] { return ~[ ] ; }
236
218
let vals = vec:: to_mut ( vec:: from_fn ( n_opts, f) ) ;
@@ -366,12 +348,12 @@ fn opt_vals(+mm: Matches, nm: &str) -> ~[Optval] {
366
348
fn opt_val( +mm: Matches , nm: & str ) -> Optval { return opt_vals ( mm, nm) [ 0 ] ; }
367
349
368
350
/// 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 {
370
352
return vec:: len :: < Optval > ( opt_vals ( mm, nm) ) > 0 u;
371
353
}
372
354
373
355
/// 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 {
375
357
for vec:: each( names) |nm| {
376
358
match find_opt ( mm. opts , mkname ( * nm) ) {
377
359
Some ( _) => return true ,
@@ -388,7 +370,7 @@ fn opts_present(+mm: Matches, names: &[~str]) -> bool {
388
370
* Fails if the option was not matched or if the match did not take an
389
371
* argument
390
372
*/
391
- fn opt_str ( +mm : Matches , nm : & str ) -> ~str {
373
+ pub fn opt_str ( +mm : Matches , nm : & str ) -> ~str {
392
374
return match opt_val ( mm, nm) { Val ( copy s) => s, _ => fail } ;
393
375
}
394
376
@@ -398,7 +380,7 @@ fn opt_str(+mm: Matches, nm: &str) -> ~str {
398
380
* Fails if the no option was provided from the given list, or if the no such
399
381
* option took an argument
400
382
*/
401
- fn opts_str ( +mm : Matches , names : & [ ~str ] ) -> ~str {
383
+ pub fn opts_str ( +mm : Matches , names : & [ ~str ] ) -> ~str {
402
384
for vec:: each( names) |nm| {
403
385
match opt_val ( mm, * nm) {
404
386
Val ( copy s) => return s,
@@ -415,7 +397,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str {
415
397
*
416
398
* Used when an option accepts multiple values.
417
399
*/
418
- fn opt_strs ( +mm : Matches , nm : & str ) -> ~[ ~str ] {
400
+ pub fn opt_strs ( +mm : Matches , nm : & str ) -> ~[ ~str ] {
419
401
let mut acc: ~[ ~str ] = ~[ ] ;
420
402
for vec:: each( opt_vals( mm, nm) ) |v| {
421
403
match * v { Val ( copy s) => acc. push ( s) , _ => ( ) }
@@ -424,7 +406,7 @@ fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] {
424
406
}
425
407
426
408
/// 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 > {
428
410
let vals = opt_vals ( mm, nm) ;
429
411
if vec:: len :: < Optval > ( vals) == 0 u { return None :: < ~str > ; }
430
412
return match vals[ 0 ] {
@@ -441,7 +423,7 @@ fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> {
441
423
* present but no argument was provided, and the argument if the option was
442
424
* present and an argument was provided.
443
425
*/
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 > {
445
427
let vals = opt_vals ( mm, nm) ;
446
428
if vec:: len :: < Optval > ( vals) == 0 u { return None :: < ~str > ; }
447
429
return match vals[ 0 ] { Val ( copy s) => Some :: < ~str > ( s) ,
0 commit comments