Skip to content

Commit 789b278

Browse files
committed
---
yaml --- r: 2723 b: refs/heads/master c: 3a2d64f h: refs/heads/master i: 2721: 8cc429c 2719: 3569053 v: v3
1 parent 90cd4ac commit 789b278

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a0f855e48812d8ce5c0c2d4e7496aa0e4643bdb3
2+
refs/heads/master: 3a2d64f04404142cb2769aaaa57c101b258eef72

trunk/src/lib/getopts.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ tag occur { req; optional; multi; }
3838
type opt = rec(name name, hasarg hasarg, occur occur);
3939

4040
fn mkname(str nm) -> name {
41-
if (str::char_len(nm) == 1u) { ret short(str::char_at(nm, 0u)); }
42-
else { ret long(nm); }
41+
ret if (str::char_len(nm) == 1u) {
42+
short(str::char_at(nm, 0u))
43+
} else {
44+
long(nm)
45+
};
4346
}
4447
fn reqopt(str name) -> opt {
4548
ret rec(name=mkname(name), hasarg=yes, occur=req);
@@ -65,23 +68,23 @@ fn is_arg(str arg) -> bool {
6568
ret str::byte_len(arg) > 1u && arg.(0) == '-' as u8;
6669
}
6770
fn name_str(name nm) -> str {
68-
alt (nm) {
69-
case (short(?ch)) {ret str::from_char(ch);}
70-
case (long(?s)) {ret s;}
71-
}
71+
ret alt (nm) {
72+
case (short(?ch)) {str::from_char(ch)}
73+
case (long(?s)) {s}
74+
};
7275
}
7376

7477
// FIXME rustboot workaround
7578
fn name_eq(name a, name b) -> bool {
76-
alt (a) {
79+
ret alt (a) {
7780
case (long(?a)) {
7881
alt (b) {
79-
case (long(?b)) { ret str::eq(a, b); }
80-
case (_) { ret false; }
82+
case (long(?b)) { str::eq(a, b) }
83+
case (_) { false }
8184
}
8285
}
83-
case (_) { if (a == b) { ret true; } else {ret false; } }
84-
}
86+
case (_) { if (a == b) { true } else { false } }
87+
};
8588
}
8689
fn find_opt(vec[opt] opts, name nm) -> option::t[uint] {
8790
auto i = 0u;
@@ -102,23 +105,23 @@ tag fail_ {
102105
}
103106

104107
fn fail_str(fail_ f) -> str {
105-
alt (f) {
108+
ret alt (f) {
106109
case (argument_missing(?nm)) {
107-
ret "Argument to option '" + nm + "' missing.";
110+
"Argument to option '" + nm + "' missing."
108111
}
109112
case (unrecognized_option(?nm)) {
110-
ret "Unrecognized option: '" + nm + "'.";
113+
"Unrecognized option: '" + nm + "'."
111114
}
112115
case (option_missing(?nm)) {
113-
ret "Required option '" + nm + "' missing.";
116+
"Required option '" + nm + "' missing."
114117
}
115118
case (option_duplicated(?nm)) {
116-
ret "option '" + nm + "' given more than once.";
119+
"option '" + nm + "' given more than once."
117120
}
118121
case (unexpected_argument(?nm)) {
119-
ret "Option " + nm + " does not take an argument.";
122+
"Option " + nm + " does not take an argument."
120123
}
121-
}
124+
};
122125
}
123126

124127
tag result {
@@ -228,13 +231,13 @@ fn getopts(vec[str] args, vec[opt] opts) -> result {
228231
}
229232

230233
fn opt_vals(match m, str nm) -> vec[optval] {
231-
alt (find_opt(m.opts, mkname(nm))) {
232-
case (some[uint](?id)) { ret m.vals.(id); }
234+
ret alt (find_opt(m.opts, mkname(nm))) {
235+
case (some[uint](?id)) { m.vals.(id) }
233236
case (none[uint]) {
234237
log_err "No option '" + nm + "' defined.";
235-
fail;
238+
fail
236239
}
237-
}
240+
};
238241
}
239242
fn opt_val(match m, str nm) -> optval {
240243
ret opt_vals(m, nm).(0);
@@ -243,10 +246,10 @@ fn opt_present(match m, str nm) -> bool {
243246
ret vec::len[optval](opt_vals(m, nm)) > 0u;
244247
}
245248
fn opt_str(match m, str nm) -> str {
246-
alt (opt_val(m, nm)) {
247-
case (val(?s)) { ret s; }
248-
case (_) { fail; }
249-
}
249+
ret alt (opt_val(m, nm)) {
250+
case (val(?s)) { s }
251+
case (_) { fail }
252+
};
250253
}
251254
fn opt_strs(match m, str nm) -> vec[str] {
252255
let vec[str] acc = [];
@@ -261,10 +264,10 @@ fn opt_strs(match m, str nm) -> vec[str] {
261264
fn opt_maybe_str(match m, str nm) -> option::t[str] {
262265
auto vals = opt_vals(m, nm);
263266
if (vec::len[optval](vals) == 0u) { ret none[str]; }
264-
alt (vals.(0)) {
265-
case (val(?s)) { ret some[str](s); }
266-
case (_) { ret none[str]; }
267-
}
267+
ret alt (vals.(0)) {
268+
case (val(?s)) { some[str](s) }
269+
case (_) { none[str] }
270+
};
268271
}
269272

270273
// Local Variables:

0 commit comments

Comments
 (0)