Download
31 lines 1.2 KiBNomsuModified 2019-03-27 raw
1234567891011121314151617181920212223242526272829303132
#!/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 \(at \("Text" tree with "\($cmd.source)") =sh \$cmd)
    (sh> $cmd) compiles to \(at \("Text" tree with "\($cmd.source)") sh> \$cmd)