Skip to main content

rl_lang/docs/entries/stdlib/process/
mod.rs

1use crate::docs::entry::{FnEntry, StdEntry};
2
3pub static PROCESS: StdEntry = StdEntry {
4    name: "process",
5    description: "functions for interacting with the current process and running shell commands",
6    functions: FUNCTIONS,
7    since: None,
8    unstable: false,
9};
10
11static FUNCTIONS: &[&FnEntry] = &[
12    &ARGS,
13    &CWD,
14    &ENV,
15    &EXEC,
16    &EXEC_CODE,
17    &EXEC_LINES,
18    &EXIT,
19    &PID,
20    &SET_CWD,
21    &SLEEP,
22];
23
24static ARGS: FnEntry = FnEntry {
25    signature: "args()",
26    description: "returns the command-line arguments passed to the script as an array of strings",
27    example: "get std::process::args\n\ndec string[] a = args()\nprintln(a) // [\"--verbose\", \"input.txt\"]",
28    expected_output: None,
29    returns: "",
30    errors: None,
31    see_also: &[],
32    since: None,
33};
34
35static CWD: FnEntry = FnEntry {
36    signature: "cwd()",
37    description: "returns the current working directory as a string",
38    example: "get std::process::cwd\n\nprintln(cwd()) // \"/home/crimson/project\"",
39    expected_output: None,
40    returns: "",
41    errors: None,
42    see_also: &[],
43    since: None,
44};
45
46static SET_CWD: FnEntry = FnEntry {
47    signature: "set_cwd(path)",
48    description: "changes the current working directory",
49    example: "get std::process::set_cwd\n\nset_cwd(\"/tmp\")",
50    expected_output: None,
51    returns: "",
52    errors: None,
53    see_also: &[],
54    since: None,
55};
56
57static ENV: FnEntry = FnEntry {
58    signature: "env(key)",
59    description: "returns the value of an environment variable, or null if not set",
60    example: "get std::process::env\n\nprintln(env(\"HOME\")) // \"/home/crimson\"",
61    expected_output: None,
62    returns: "",
63    errors: None,
64    see_also: &[],
65    since: None,
66};
67
68static EXIT: FnEntry = FnEntry {
69    signature: "exit(code)",
70    description: "terminates the process with the given exit code",
71    example: "get std::process::exit\n\nexit(0)  // success\nexit(1)  // error",
72    expected_output: None,
73    returns: "",
74    errors: None,
75    see_also: &[],
76    since: None,
77};
78
79static PID: FnEntry = FnEntry {
80    signature: "pid()",
81    description: "returns the process ID of the current process",
82    example: "get std::process::pid\n\nprintln(pid()) // 12345",
83    expected_output: None,
84    returns: "",
85    errors: None,
86    see_also: &[],
87    since: None,
88};
89
90static SLEEP: FnEntry = FnEntry {
91    signature: "sleep(ms)",
92    description: "pauses the process for the given number of milliseconds",
93    example: "get std::process::sleep\n\nsleep(1000) // wait 1 second",
94    expected_output: None,
95    returns: "",
96    errors: None,
97    see_also: &[],
98    since: None,
99};
100
101static EXEC: FnEntry = FnEntry {
102    signature: "exec(cmd)",
103    description: "runs a shell command and returns its stdout as a trimmed string",
104    example: "get std::process::exec\n\ndec string out = exec(\"echo hello\")\nprintln(out) // \"hello\"",
105    expected_output: None,
106    returns: "",
107    errors: None,
108    see_also: &[],
109    since: None,
110};
111
112static EXEC_CODE: FnEntry = FnEntry {
113    signature: "exec_code(cmd)",
114    description: "runs a shell command and returns its exit code as an int",
115    example: "get std::process::exec_code\n\ndec int code = exec_code(\"ls /nonexistent\")\nprintln(code) // 2",
116    expected_output: None,
117    returns: "",
118    errors: None,
119    see_also: &[],
120    since: None,
121};
122
123static EXEC_LINES: FnEntry = FnEntry {
124    signature: "exec_lines(cmd)",
125    description: "runs a shell command and returns its stdout split into an array of lines",
126    example: "get std::process::exec_lines\n\ndec string[] files = exec_lines(\"ls src\")\nprintln(files) // [\"main.rl\", \"lib.rl\"]",
127    expected_output: None,
128    returns: "",
129    errors: None,
130    see_also: &[],
131    since: None,
132};