Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions baseio/builtins_baseio.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ var builtins_baseio = map[string]*env.Builtin{
// Process / shell
// -------------------------------------------------------------------------

// Tests:
// equal { scmd "exit 0" } 0
// equal { scmd "exit 3" } 3
// error { scmd 123 }
// Args:
// * cmd: Shell command string to execute
// Returns:
// * integer exit status code
"scmd": {
Argsn: 1,
Doc: "Execute a shell command and return its exit status code.",
Expand All @@ -229,6 +237,13 @@ var builtins_baseio = map[string]*env.Builtin{
},
},

// Tests:
// equal { scmd\capture "echo hi" } "hi\n"
// error { scmd\capture 123 }
// Args:
// * cmd: Shell command string to execute and capture output
// Returns:
// * string containing captured stdout (stderr on error)
"scmd\\capture": {
Argsn: 1,
Doc: "Execute a shell command and capture the output, return it as string",
Expand Down Expand Up @@ -259,6 +274,8 @@ var builtins_baseio = map[string]*env.Builtin{
},
},

// Example:
// ; exit 0
"exit": { // **
Argsn: 1,
Doc: "Exits the process with the given integer status code (or 0 for any non-integer).",
Expand All @@ -280,6 +297,8 @@ var builtins_baseio = map[string]*env.Builtin{
// Rye-itself - args / history (requires os.Args / process context)
// -------------------------------------------------------------------------

// Example:
// Rye-itself//args?
"Rye-itself//args?": {
Argsn: 0,
Doc: "Returns command line arguments as a block of parsed values. Each argument is converted to appropriate type (integer, float, or string).",
Expand All @@ -288,6 +307,8 @@ var builtins_baseio = map[string]*env.Builtin{
},
},

// Example:
// Rye-itself//Args?
"Rye-itself//Args?": {
Argsn: 0,
Doc: "Returns command line arguments as a block of parsed values. Each argument is converted to appropriate type (integer, float, or string).",
Expand All @@ -296,6 +317,8 @@ var builtins_baseio = map[string]*env.Builtin{
},
},

// Example:
// Rye-itself//Args\\raw?
"Rye-itself//Args\\raw?": {
Argsn: 1,
Doc: "Returns raw command line arguments joined as a single string.",
Expand All @@ -308,6 +331,8 @@ var builtins_baseio = map[string]*env.Builtin{
},
},

// Example:
// Rye-itself//History? 10 ; last 10 lines (when running under REPL)
"Rye-itself//History?": {
Argsn: 2,
Doc: "Returns a block of the last N lines from REPL history.",
Expand All @@ -333,6 +358,9 @@ var builtins_baseio = map[string]*env.Builtin{
// stdout capture
// -------------------------------------------------------------------------

// Tests:
// equal { capture-stdout { print 1 } } "1\n"
// error { capture-stdout 1 }
"capture-stdout": { // **
Argsn: 1,
Doc: "Executes a block of code while capturing all output to stdout, returning the captured output as a string.",
Expand Down
31 changes: 31 additions & 0 deletions baseio/builtins_printing.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ func DisplayRyeValue(ps *env.ProgramState, arg0 env.Object, interactive bool) (e
// registered by evaldo.RegisterBaseBuiltins and do not require these deps.
var builtins_printing_extra = map[string]*env.Builtin{

// Example:
// display [1 2 3]
// Args:
// * value: Block, Dict, Table, TableRow, Markdown, or Error to display interactively
// Returns:
// * the selected value or the original value when user exits
"display": {
Pure: true,
Argsn: 1,
Expand All @@ -161,6 +167,12 @@ var builtins_printing_extra = map[string]*env.Builtin{
},
},

// Example:
// _.. [1 2 3]
// Args:
// * value: Block, Dict, Table, TableRow, Markdown, or Error to display interactively
// Returns:
// * the selected value or the original value when user exits
"_..": {
Argsn: 1,
Doc: "Shorthand alias for 'display' - interactively displays a value in the terminal with navigation capabilities.",
Expand Down Expand Up @@ -222,6 +234,13 @@ var builtins_printing_extra = map[string]*env.Builtin{
},
},

// Example:
// table { "n" } { 1 2 3 } |display\custom fn { row is-curr } { if is-curr > 0 { print "*" } print row }
// Args:
// * table: Table to display
// * renderer: Function called for each row with args (row is-current)
// Returns:
// * the selected row or original table when user exits
"display\\custom": {
Argsn: 2,
Doc: "Interactively displays a Table in the terminal with a custom rendering function for each row.",
Expand Down Expand Up @@ -252,6 +271,12 @@ var builtins_printing_extra = map[string]*env.Builtin{
},
},

// Tests:
// stdout { print\ssv { 1 2 "a" } } "1 2 a\n"
// Args:
// * values: Block to format as space-separated values
// Returns:
// * returns the input block after printing
"print\\ssv": {
Argsn: 1,
Doc: "Prints a block of values as space-separated values followed by a newline, returning the input block.",
Expand All @@ -266,6 +291,12 @@ var builtins_printing_extra = map[string]*env.Builtin{
},
},

// Tests:
// stdout { print\csv { 1 2 "a" } } "1,2,a\n"
// Args:
// * values: Block to format as comma-separated values
// Returns:
// * returns the input block after printing
"print\\csv": {
Argsn: 1,
Doc: "Prints a block of values as comma-separated values followed by a newline, returning the input block.",
Expand Down
21 changes: 21 additions & 0 deletions batteries/builtins_bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ var Builtins_bcrypt = map[string]*env.Builtin{
// * password: String to hash
// Returns:
// * string containing the bcrypt hash of the password
// Tests:
// equal { bcrypt-hash "secret" |type? } 'string
// Args:
// * password: String to hash
// Returns:
// * string containing the bcrypt hash of the password
"bcrypt-hash": {
Argsn: 1,
Doc: "Generates a bcrypt hash from a password string.",
Expand All @@ -87,6 +93,14 @@ var Builtins_bcrypt = map[string]*env.Builtin{
// * password: Plain text password to compare
// Returns:
// * integer 1 if the password matches the hash, 0 otherwise
// Tests:
// equal { bcrypt-check "$2a$10$N9qo8uLOickgx2ZMRZo4e.PFTlCOKQOLawQy5AdYyZuG7JC2rA9e." "password" } 1
// equal { bcrypt-check "$2a$10$N9qo8uLOickgx2ZMRZo4e.PFTlCOKQOLawQy5AdYyZuG7JC2rA9e." "wrong" } 0
// Args:
// * hash: String containing the bcrypt hash
// * password: Plain text password to compare
// Returns:
// * integer 1 if the password matches the hash, 0 otherwise
"bcrypt-check": {
Argsn: 2,
Doc: "Compares a bcrypt hash with a plain text password.",
Expand All @@ -100,6 +114,13 @@ var Builtins_bcrypt = map[string]*env.Builtin{
// * length: Integer number of random bytes to generate
// Returns:
// * string containing the hex-encoded random token
// Tests:
// equal { generate-token 4 |length? } 8
// error { generate-token "x" }
// Args:
// * length: Integer number of random bytes to generate
// Returns:
// * string containing the hex-encoded random token
"generate-token": {
Argsn: 1,
Doc: "Generates a cryptographically secure random token of the specified length in bytes.",
Expand Down
4 changes: 4 additions & 0 deletions batteries/builtins_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ var Builtins_http = map[string]*env.Builtin{
// * native Go-server object that can handle HTTP requests
"http-server": {
Argsn: 1,
// Example:
// srv: http-server ":8080"
// srv .Handle "/" "Hello world!"
// ; srv .Serve ; blocks and serves requests
Doc: "Creates a new HTTP server that listens on the specified address with a 10-second read header timeout.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch addr := arg0.(type) {
Expand Down
10 changes: 5 additions & 5 deletions batteries/builtins_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func BlockToJSONWithIdxs(block env.Block, idxs *env.Idxs) string {
}
bu.WriteString(RyeToJSONWithIdxs(val, idxs))
}
bu.WriteString("] ")
bu.WriteString("]")
return bu.String()
}

Expand All @@ -212,7 +212,7 @@ func ListToJSONWithIdxs(list env.List, idxs *env.Idxs) string {
}
bu.WriteString(RyeToJSONWithIdxs(val, idxs))
}
bu.WriteString("] ")
bu.WriteString("]")
return bu.String()
}

Expand All @@ -235,7 +235,7 @@ func DictToJSONWithIdxs(dict env.Dict, idxs *env.Idxs) string {
bu.WriteString(RyeToJSONWithIdxs(val, idxs))
i = i + 1
}
bu.WriteString("} ")
bu.WriteString("}")
return bu.String()
}

Expand All @@ -255,7 +255,7 @@ func ContextToJSON(ctx *env.RyeCtx, idxs *env.Idxs) string {
bu.WriteString(RyeToJSONWithIdxs(val, idxs))
i = i + 1
}
bu.WriteString("} ")
bu.WriteString("}")
return bu.String()
}

Expand All @@ -277,7 +277,7 @@ func TableRowToJSONWithIdxs(row env.TableRow, idxs *env.Idxs) string {
bu.WriteString("\": ")
bu.WriteString(RyeToJSONWithIdxs(val, idxs))
}
bu.WriteString("} ")
bu.WriteString("}")
return bu.String()
}

Expand Down
Loading
Loading