Skip to content

Commit

Permalink
new script ability, 'system_unload' this executes a system command wh…
Browse files Browse the repository at this point in the history
…en unloading the module
  • Loading branch information
Frederik Delaere committed Oct 10, 2019
1 parent 862de3d commit 378f2a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Next to the default rhai syntax, the following functions are available:
* ```append_path("variable","value");```
* ```remove_path("variable","value");```
* ```system("command");```
* ```system_unload("command");``` This command is only executed when unloading the module
* ```load("modulename");```
* ```unload("modulename");```
* ```conflict("modulename");```
Expand Down Expand Up @@ -184,6 +185,9 @@ prepend_path("PATH","/software/shared/apps/iprscan/5.23-62/");
system("mkdir -p /scratch/tmp/iprscan_logs");
system("mkdir -p /scratch/tmp/iprscan_tmp");

system("source activate myprogram");
system_unload("source deactivate");

source("bash", "/software/shared/apps/iprscan/5.23-64/env.sh");
source("zsh", "/software/shared/apps/iprscan/5.23-64/env.zsh");

Expand Down
15 changes: 14 additions & 1 deletion src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
extern crate rhai;
//extern crate is_executable;

use self::rhai::{Engine, FnRegister};
use super::super::bold;
use super::{echo, get_shell_info, Rsmodule};
Expand Down Expand Up @@ -392,6 +392,14 @@ fn system(cmd: String) {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))]
fn system_unload(cmd: String) {
let (shell, _) = get_shell_info();
if shell != "python" && shell != "perl" {
add_to_commands(&cmd);
}
}

#[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))]
fn load(module: String) {
let (shell, _) = get_shell_info();
Expand Down Expand Up @@ -485,6 +493,7 @@ pub fn run(path: &PathBuf, action: &str) {
engine.register_fn("append_path", remove_path);
engine.register_fn("remove_path", remove_path_dummy);
engine.register_fn("system", system_dummy);
engine.register_fn("system_unload", system_unload);
engine.register_fn("load", load_dummy);
engine.register_fn("conflict", conflict_dummy);
engine.register_fn("unload", unload_dummy);
Expand All @@ -502,6 +511,7 @@ pub fn run(path: &PathBuf, action: &str) {
engine.register_fn("append_path", append_path);
engine.register_fn("remove_path", remove_path);
engine.register_fn("system", system);
engine.register_fn("system_unload", system_dummy);
engine.register_fn("load", load);
engine.register_fn("conflict", conflict);
engine.register_fn("unload", unload);
Expand All @@ -519,6 +529,7 @@ pub fn run(path: &PathBuf, action: &str) {
engine.register_fn("append_path", append_path_info);
engine.register_fn("remove_path", remove_path_dummy);
engine.register_fn("system", system_dummy);
engine.register_fn("system_unload", system_dummy);
engine.register_fn("load", load_info);
engine.register_fn("conflict", conflict_dummy);
engine.register_fn("unload", unload_dummy);
Expand All @@ -536,6 +547,7 @@ pub fn run(path: &PathBuf, action: &str) {
engine.register_fn("append_path", append_path_dummy);
engine.register_fn("remove_path", remove_path_dummy);
engine.register_fn("system", system_dummy);
engine.register_fn("system_unload", system_dummy);
engine.register_fn("load", load_dummy);
engine.register_fn("conflict", conflict_dummy);
engine.register_fn("unload", unload_dummy);
Expand All @@ -553,6 +565,7 @@ pub fn run(path: &PathBuf, action: &str) {
engine.register_fn("append_path", readme_path);
engine.register_fn("remove_path", remove_path_dummy);
engine.register_fn("system", system_dummy);
engine.register_fn("system_unload", system_dummy);
engine.register_fn("load", load_dummy);
engine.register_fn("conflict", conflict_dummy);
engine.register_fn("unload", unload_dummy);
Expand Down

0 comments on commit 378f2a6

Please sign in to comment.