summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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():