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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use bincode::rustc_serialize::{DecodingResult, EncodingResult};
#[macro_use]
mod util;
pub mod info;
mod mount;
mod run;
pub mod shim;
pub trait KageCommand {
fn get_name<'a>(&'a self) -> &'a String;
fn get_usage(&self) -> String;
fn call(&mut self, args: &Vec<String>) -> Result<(), String>;
}
#[derive(Debug, RustcDecodable, RustcEncodable)]
pub enum PortalCall {
Run(run::RunAction),
Info(info::InfoAction),
}
impl_encdec!(PortalCall);
#[derive(Debug, RustcDecodable, RustcEncodable)]
pub enum MonitorCall {
Mount(mount::MountAction),
Shim(shim::ShimAction),
}
impl_encdec!(MonitorCall);
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
pub struct PortalAck {
pub request: PortalRequest,
}
impl_encdec!(PortalAck);
#[derive(Clone, Copy, Debug, RustcDecodable, RustcEncodable)]
pub enum PortalRequest {
Nop,
CreateTty,
}
fn list_kage_cmds<'a>() -> Vec<Box<KageCommand + 'a>> {
vec!(
Box::new(self::info::InfoKageCmd::new()) as Box<KageCommand>,
Box::new(self::mount::MountKageCmd::new()) as Box<KageCommand>,
Box::new(self::run::RunKageCmd::new()) as Box<KageCommand>,
Box::new(self::shim::ShimKageCmd::new()) as Box<KageCommand>,
)
}
pub fn get_kage_cmd(name: &String) -> Option<Box<KageCommand>> {
for cmd in list_kage_cmds().into_iter() {
if cmd.get_name() == name {
return Some(cmd);
}
}
None
}
pub fn list_kage_cmd_names() -> Vec<String> {
list_kage_cmds().iter().map(|x| x.get_name().clone()).collect()
}