diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-24 15:20:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-24 15:20:19 -0400 |
| commit | b289b09bdeea84e233e26267d33e3338c8dba084 (patch) | |
| tree | 73108ca4b475738b618d6870a67d5b1aedcfaa26 /examples/commands/commands.tm | |
| parent | 454cb1ce1d8a35f712139e0ae5958370d6d56e81 (diff) | |
Add some exit type methods
Diffstat (limited to 'examples/commands/commands.tm')
| -rw-r--r-- | examples/commands/commands.tm | 9 |
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): |
