aboutsummaryrefslogtreecommitdiff
path: root/lib/shell/init.nom
blob: 13dc675ce2bd9f64a93ab061020735030bc42d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env nomsu -V7.0.0

###
    This file defines some actions for running shell commands.
    
external:
    (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
        ("Action" tree with "at" ("Text" tree with "\($cmd.source)") "=" "sh" $cmd) as lua
    
    (sh> $cmd) compiles to
        ("Action" tree with "at" ("Text" tree with "\($cmd.source)") "sh" ">" $cmd) as lua