diff options
-rwxr-xr-x | vish.py | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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(): |