diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-17 19:29:28 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-17 19:29:28 -0400 |
| commit | 0bba31912665a82f848642e6b4247071a3ee177a (patch) | |
| tree | ae5c3ac7501a0841c9a858d6559a0dfb7db69035 /examples/shell | |
| parent | 94993c5f113b27083e586c7620eb896fe750c6d1 (diff) | |
Big overhaul:
- Clean up environment code using type strings instead of manually
defining types
- Add Commands module
- Move Shell lang into an example module that uses Commands module
- Fix some bugs with chained library dependencies
Diffstat (limited to 'examples/shell')
| -rw-r--r-- | examples/shell/shell.tm | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/shell/shell.tm b/examples/shell/shell.tm new file mode 100644 index 00000000..cf5fcd2e --- /dev/null +++ b/examples/shell/shell.tm @@ -0,0 +1,35 @@ +use commands + +lang Shell: + convert(text:Text -> Shell): + return Shell.from_text("'" ++ text:replace($/'/, `'"'"'`) ++ "'") + + convert(texts:[Text] -> Shell): + return Shell.from_text(" ":join([Shell(t).text for t in texts])) + + convert(path:Path -> Shell): + return Shell(Text(path:expand_home())) + + convert(paths:[Path] -> Shell): + return Shell.from_text(" ":join([Shell(Text(p)).text for p in paths])) + + convert(n:Int -> Shell): return Shell.from_text(Text(n)) + convert(n:Int64 -> Shell): return Shell.from_text(Text(n)) + convert(n:Int32 -> Shell): return Shell.from_text(Text(n)) + convert(n:Int16 -> Shell): return Shell.from_text(Text(n)) + convert(n:Int8 -> Shell): return Shell.from_text(Text(n)) + convert(n:Num -> Shell): return Shell.from_text(Text(n)) + convert(n:Num32 -> Shell): return Shell.from_text(Text(n)) + + func command(shell:Shell -> Command): + return Command("sh", ["-c", shell.text]) + + func run(shell:Shell, input="", input_bytes=[:Byte] -> ProgramResult): + return shell:command():run(input=input, input_bytes=input_bytes) + + func get_output(shell:Shell, input="", trim_newline=yes -> Text?): + return shell:command():get_output(input=input, trim_newline=trim_newline) + + func get_output_bytes(shell:Shell, input="", input_bytes=[:Byte] -> [Byte]?): + return shell:command():get_output_bytes(input=input, input_bytes=input_bytes) + |
