-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.jk
52 lines (38 loc) · 1016 Bytes
/
shell.jk
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
ext func system(s: string) -> int;
func shell_execute_string(s: string) -> int {
system(s)
}
// FIXME: Add documentation
// FIXME: Should return a Result
func shell(s: string) -> int {
shell_execute_string(s)
}
// FIXME: The command type should store stdout and stderr
type Cmd(s: string);
func cmd(command: string) -> Cmd {
// FIXME: Make sure `command` does not contain any spaces
Cmd(s: command)
}
func with_arg(cmd: Cmd, arg: string) -> Cmd {
mut new_s = concat(cmd.s, " ");
new_s = new_s.concat(arg);
Cmd(s: new_s)
}
// FIXME: Should return a Result
func execute(cmd: Cmd) -> int {
shell(cmd.s)
}
test shell_execute_cmd() {
shell("pwd");
// FIXME: Redirect this output
// FIXME: Add assertions
}
test shell_builder_pattern() {
mut c = cmd("ls");
c = c.with_arg("thisdir");
// FIXME: Add assertions
}
test shell_builder_pattern_inline() {
mut c = cmd("ls").with_arg("-l").with_arg("-a").with_arg("thidir");
// FIXME: Add assertions
}