docs: fix description for hilbish.run, add example

pull/291/head
sammyette 2024-04-27 20:53:45 -04:00
parent a3b17c5301
commit b8e3d4d8e6
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 20 additions and 3 deletions

23
api.go
View File

@ -185,14 +185,31 @@ func handleStream(v rt.Value, strms *streams, errStream bool) error {
// run(cmd, streams) -> exitCode (number), stdout (string), stderr (string) // run(cmd, streams) -> exitCode (number), stdout (string), stderr (string)
// Runs `cmd` in Hilbish's shell script interpreter. // Runs `cmd` in Hilbish's shell script interpreter.
// #param cmd string // The `streams` parameter specifies the output and input streams the command should use.
// #param streams table|boolean
// Specifies the output and input streams the command should use.
// For example, to write command output to a sink. // For example, to write command output to a sink.
// As a table, the caller can directly specify the standard output, error, and input // As a table, the caller can directly specify the standard output, error, and input
// streams of the command with the table keys `out`, `err`, and `input` respectively. // streams of the command with the table keys `out`, `err`, and `input` respectively.
// As a boolean, it specifies whether the command should use standard output or return its output streams. // As a boolean, it specifies whether the command should use standard output or return its output streams.
// #param cmd string
// #param streams table|boolean
// #returns number, string, string // #returns number, string, string
// #example
/*
// This code is the same as `ls -l | wc -l`
local fs = require 'fs'
local pr, pw = fs.pipe()
hilbish.run('ls -l', {
stdout = pw,
stderr = pw,
})
pw:close()
hilbish.run('wc -l', {
stdin = pr
})
*/
// #example
func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// TODO: ON BREAKING RELEASE, DO NOT ACCEPT `streams` AS A BOOLEAN. // TODO: ON BREAKING RELEASE, DO NOT ACCEPT `streams` AS A BOOLEAN.
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {