From b289b09bdeea84e233e26267d33e3338c8dba084 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 24 Mar 2025 15:20:19 -0400 Subject: [PATCH] Add some exit type methods --- examples/commands/commands.tm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/commands/commands.tm b/examples/commands/commands.tm index dd366f6..348796d 100644 --- a/examples/commands/commands.tm +++ b/examples/commands/commands.tm @@ -6,7 +6,14 @@ use libunistring.so extern run_command:func(exe:Text, args:[Text], env:{Text,Text}, input:[Byte]?, output:&[Byte]?, error:&[Byte]? -> Int32) extern command_by_line:func(exe:Text, args:[Text], env:{Text,Text} -> func(->Text?)?) -enum ExitType(Exited(status:Int32), Signaled(signal:Int32), Failed) +enum ExitType(Exited(status:Int32), Signaled(signal:Int32), Failed): + func succeeded(e:ExitType -> Bool): + when e is Exited(status): return (status == 0) + else: return no + + func or_fail(e:ExitType -> ExitType): + if e:succeeded(): return e + fail("Program failed: $e") struct ProgramResult(stdout:[Byte], stderr:[Byte], exit_type:ExitType): func or_fail(r:ProgramResult -> ProgramResult):