aboutsummaryrefslogtreecommitdiff
path: root/lib/shell
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-18 14:22:17 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-18 14:22:48 -0800
commit10bd72e858a8ffaacafa296dbbc429dc73b0111c (patch)
tree3dec18257ac6d1affe78aa33a9b389a25eda1256 /lib/shell
parent520acd39795766354fc44c6e15f5f33f255ca33a (diff)
Added `tree` back as a parameter to compile actions, which helps with
better error reporting, e.g. for (fail) (no arguments). Overall better error reporting now. Also added shorthand ("Action" tree with ...) for (SyntaxTree {.type = "Action", .1 = ...}).
Diffstat (limited to 'lib/shell')
-rw-r--r--lib/shell/init.nom32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/shell/init.nom b/lib/shell/init.nom
index d58894e..13dde56 100644
--- a/lib/shell/init.nom
+++ b/lib/shell/init.nom
@@ -1,12 +1,26 @@
#
This file defines some actions for running shell commands.
-
+
external:
- (=sh $cmd) means:
- lua> ("
- local result = io.popen(\$cmd)
- local contents = result:read("*a")
- result:close()
- return contents
- ")
- $(sh> $) = $os.execute
+ (at $callsite =sh $cmd) means:
+ $f = ($io.popen $cmd)
+ $contents = ($f, read "*a")
+ [$ok, $return_type, $return] = ($f, close)
+ unless $ok:
+ if ($return_type == "exit"):
+ at $callsite fail "Command failure: Command `\$cmd` failed with exit code \$return"
+ ..else:
+ at $callsite fail "Command failure: Command `\$cmd` was terminated by signal \$return"
+ return $contents
+
+ (at $callsite sh> $cmd) means:
+ [$ok, $return_type, $return] = ($os.execute $cmd)
+ unless $ok:
+ if ($return_type == "exit"):
+ at $callsite fail "Command failure: Command `\$cmd` failed with exit code \$return"
+ ..else:
+ at $callsite fail "Command failure: Command `\$cmd` was terminated by signal \$return"
+
+ # Attach callsite information for better error reporting
+ (=sh $cmd) compiles to (\(at ("Text" tree with "\($cmd.source)") =sh $cmd) as lua)
+ (sh> $cmd) compiles to (\(at ("Text" tree with "\($cmd.source)") sh> $cmd) as lua)