From 68410f0da2af88cd8ecec99f46e1121aa6d8cc3c Mon Sep 17 00:00:00 2001 From: Danny Rosseau <daniel.rosseau@gmail.com> Date: Tue, 18 Jul 2017 11:12:16 -0600 Subject: [PATCH] Added not builtin --- examples/not.ion | 6 ++++++ examples/not.out | 6 ++++++ src/builtins/mod.rs | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 examples/not.ion create mode 100644 examples/not.out diff --git a/examples/not.ion b/examples/not.ion new file mode 100644 index 00000000..ef5f4b36 --- /dev/null +++ b/examples/not.ion @@ -0,0 +1,6 @@ +not true || echo not true +not false && echo not false +true && not false && echo true and not false +not test -z "a" && echo not test +not echo hello +echo $? \ No newline at end of file diff --git a/examples/not.out b/examples/not.out new file mode 100644 index 00000000..fa385d52 --- /dev/null +++ b/examples/not.out @@ -0,0 +1,6 @@ +not true +not false +true and not false +not test +hello +-1 diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index d87aa627..60ea45d6 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -193,6 +193,20 @@ impl Builtin { }); /* Misc */ + commands.insert("not", + Builtin { + name: "not", + help: "Reverses the exit status value of the given command.", + main: Box::new(|args: &[&str], shell: &mut Shell| -> i32 { + let cmd = args[1..].join(" "); + shell.on_command(&cmd); + match shell.previous_status { + SUCCESS => FAILURE, + FAILURE => SUCCESS, + _ => shell.previous_status + } + }), + }); commands.insert("set", Builtin { name: "set", -- GitLab