-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from CohenArthur/shell-library
Add shell library abstraction
- Loading branch information
Showing
7 changed files
with
157 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ incl pair | |
incl string | ||
incl maybe | ||
incl ffi | ||
incl shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
link_with("libc.so.6"); | ||
|
||
ext func system(s: string) -> int; | ||
|
||
// FIXME: Should return a Result | ||
func shell(s: string) -> int { | ||
system(s) | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
shell("echo 'from shell'") | ||
|
||
mut c = cmd("echo").with_arg("from"); | ||
c = c.with_arg("cmd"); | ||
c = c.with_arg("builder"); | ||
|
||
c.execute() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!jinko | ||
|
||
ft_exists_exit_code = shell("ft --version"); | ||
|
||
ft_exists = if ft_exists_exit_code == 0 { | ||
true | ||
} else { | ||
false | ||
}; | ||
|
||
if !ft_exists { // ft_exists.not() | ||
display_err("\n`ft` not found. Install it using the following command\n\n"); | ||
display_err("\tcargo install --git https://github.com/cohenarthur/ft\n\n"); | ||
|
||
exit(1); | ||
} | ||
|
||
shell("cargo build") | ||
|
||
if !args().empty() { | ||
display("Test files:\n"); | ||
for arg in args() { | ||
display(arg); | ||
|
||
shell("ft -f {arg}"); | ||
} | ||
} else { | ||
// Find all files somehow | ||
files = shell("find tests -name '*.yml'").output(); | ||
|
||
display("Test files:\n{files}\n\n"); | ||
|
||
shell("ft -f {files}"); | ||
} | ||
|
||
// FIXME: Parse arguments correctly | ||
// FIXME: Add split method on string | ||
// FIXME: Add string vector |