diff options
Diffstat (limited to 'lib/shell/init.nom')
| -rw-r--r-- | lib/shell/init.nom | 32 |
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) |
