1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use command::{CommandResult, ExecutableCommand};
use error::Result;
use parse_and_execute::parse_and_execute;
use parse_and_execute::parse_and_execute_command;
use parsed_parameters::get_program_parameters;
use std::env;
use std::error;
use std::process;
use std::vec::Vec;
const EXIT_SUCCESS: i32 = 0;
const EXIT_FAILURE: i32 = 1;
fn handle_result<E: error::Error>(r: Result<CommandResult<E>>) -> i32 {
match r {
Ok(command_result) => {
match command_result {
Ok(_) => EXIT_SUCCESS,
Err(e) => {
error!("{}", e);
EXIT_FAILURE
},
}
},
Err(e) => {
error!("Internal error: {}", e);
EXIT_FAILURE
},
}
}
pub fn main_impl_multiple_commands<E: error::Error>(commands: Vec<ExecutableCommand<E>>) -> ! {
process::exit(handle_result(parse_and_execute_command(env::args().next().unwrap().as_ref(),
&get_program_parameters(),
commands)));
}
pub fn main_impl_single_command<E: error::Error>(command: ExecutableCommand<E>) -> ! {
process::exit(handle_result(parse_and_execute(env::args().next().unwrap().as_ref(),
&get_program_parameters(),
command)));
}