aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-24 15:20:19 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-24 15:20:19 -0400
commitb289b09bdeea84e233e26267d33e3338c8dba084 (patch)
tree73108ca4b475738b618d6870a67d5b1aedcfaa26
parent454cb1ce1d8a35f712139e0ae5958370d6d56e81 (diff)
Add some exit type methods
-rw-r--r--examples/commands/commands.tm9
1 files changed, 8 insertions, 1 deletions
diff --git a/examples/commands/commands.tm b/examples/commands/commands.tm
index dd366f6f..348796d6 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):