@@ -32,16 +32,17 @@ extern mod rustc;
32
32
use core::prelude::*;
33
33
34
34
use core::run;
35
+ use core::libc::exit;
35
36
36
37
enum ValidUsage {
37
- Valid, Invalid
38
+ Valid(int) , Invalid
38
39
}
39
40
40
41
impl ValidUsage {
41
42
fn is_valid(&self) -> bool {
42
43
match *self {
43
- Valid => true,
44
- Invalid => false
44
+ Valid(_) => true,
45
+ Invalid => false
45
46
}
46
47
}
47
48
}
@@ -144,7 +145,7 @@ fn cmd_help(args: &[~str]) -> ValidUsage {
144
145
UsgStr(msg) => io::println(fmt!("%s\n", msg)),
145
146
UsgCall(f) => f(),
146
147
}
147
- Valid
148
+ Valid(0)
148
149
},
149
150
None => Invalid
150
151
}
@@ -162,8 +163,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
162
163
let test_exec = Path(filename).filestem().unwrap() + "test~";
163
164
invoke("rustc", &[~"--test", filename.to_owned(),
164
165
~"-o", test_exec.to_owned()], rustc::main);
165
- run::run_program(~"./" + test_exec, []);
166
- Valid
166
+ let exit_code = run::run_program(~"./" + test_exec, []);
167
+ Valid(exit_code)
167
168
}
168
169
_ => Invalid
169
170
}
@@ -175,8 +176,8 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
175
176
let exec = Path(filename).filestem().unwrap() + "~";
176
177
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
177
178
rustc::main);
178
- run::run_program(~"./"+exec, prog_args);
179
- Valid
179
+ let exit_code = run::run_program(~"./"+exec, prog_args);
180
+ Valid(exit_code)
180
181
}
181
182
_ => Invalid
182
183
}
@@ -194,7 +195,7 @@ fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
194
195
Call(f) => f(args),
195
196
CallMain(prog, f) => {
196
197
invoke(prog, args, f);
197
- Valid
198
+ Valid(0)
198
199
}
199
200
}
200
201
}
@@ -233,7 +234,10 @@ pub fn main() {
233
234
if !args.is_empty() {
234
235
for find_cmd(*args.head()).each |command| {
235
236
let result = do_command(command, args.tail());
236
- if result.is_valid() { return; }
237
+ match result {
238
+ Valid(exit_code) => unsafe { exit(exit_code.to_i32()) },
239
+ _ => loop
240
+ }
237
241
}
238
242
}
239
243
0 commit comments