Skip to content

Commit b8c7324

Browse files
committed
---
yaml --- r: 69498 b: refs/heads/auto c: ed0f014 h: refs/heads/master v: v3
1 parent 06e45fc commit b8c7324

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 0ed8713d79048ef865f8cbdcd2d2939190c75c2a
17+
refs/heads/auto: ed0f0149350be8363f93be243fe9d85e72d30fae
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libextra/getopts.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,14 @@ fn opt_vals(mm: &Matches, nm: &str) -> ~[Optval] {
369369
};
370370
}
371371

372-
fn opt_val(mm: &Matches, nm: &str) -> Optval { opt_vals(mm, nm)[0].clone() }
372+
fn opt_val(mm: &Matches, nm: &str) -> Option<Optval> {
373+
let vals = opt_vals(mm, nm);
374+
if (vals.is_empty()) {
375+
None
376+
} else {
377+
Some(opt_vals(mm, nm)[0].clone())
378+
}
379+
}
373380

374381
/// Returns true if an option was matched
375382
pub fn opt_present(mm: &Matches, nm: &str) -> bool {
@@ -400,7 +407,10 @@ pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
400407
* argument
401408
*/
402409
pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
403-
return match opt_val(mm, nm) { Val(s) => s, _ => fail!() };
410+
return match opt_val(mm, nm) {
411+
Some(Val(s)) => s,
412+
_ => fail!()
413+
};
404414
}
405415

406416
/**
@@ -412,7 +422,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
412422
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
413423
for names.iter().advance |nm| {
414424
match opt_val(mm, *nm) {
415-
Val(ref s) => return (*s).clone(),
425+
Some(Val(ref s)) => return (*s).clone(),
416426
_ => ()
417427
}
418428
}

0 commit comments

Comments
 (0)