summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2020-03-21 02:00:16 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2020-03-21 12:42:43 +0100
commited79e3d28b34e4826196529a6a7c04518c91b71f (patch)
tree4d130a1471173baf01afb01cf5a843d21f99cc28
parent18f21ff584ebf84408d28ff03b2c9fb0da8d3675 (diff)
Implement AND & OR instructions
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rwxr-xr-xvish.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/vish.py b/vish.py
index 608a8b4..8d8f6e1 100755
--- a/vish.py
+++ b/vish.py
@@ -49,7 +49,30 @@ class Instruction():
os.execvp(self.prog, [self.prog] + self.args)
else:
- os.waitpid(cpid, 0)
+ _, status = os.waitpid(cpid, 0)
+ return status
+
+
+class AndInstruction(Instruction):
+ def __init__(self, instruction1: Instruction, instruction2: Instruction):
+ self.instruction1 = instruction1
+ self.instruction2 = instruction2
+
+ def execute(self):
+ status = self.instruction1.execute()
+ if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
+ return self.instruction2.execute()
+
+
+class OrInstruction(Instruction):
+ def __init__(self, instruction1: Instruction, instruction2: Instruction):
+ self.instruction1 = instruction1
+ self.instruction2 = instruction2
+
+ def execute(self):
+ status = self.instruction1.execute()
+ if not os.WIFEXITED(status) or not os.WEXITSTATUS(status) == 0:
+ return self.instruction2.execute()
class PipelineParser():