|
| 1 | +# std.env |
| 2 | + |
| 3 | +The `std.env` module provides functions for interacting with environment variables and command-line arguments. |
| 4 | + |
| 5 | +## args() |
| 6 | + |
| 7 | +Returns command-line arguments as an array of strings. |
| 8 | + |
| 9 | +**Return Type**: `Array<string>` |
| 10 | + |
| 11 | +**Example**: |
| 12 | +```rust |
| 13 | +use std.env; |
| 14 | + |
| 15 | +// If you run: aiscript script.ai arg1 arg2 |
| 16 | +let args = env.args(); |
| 17 | +// args will be: ["aiscript", "script.ai", "arg1", "arg2"] |
| 18 | +``` |
| 19 | + |
| 20 | +## vars() |
| 21 | + |
| 22 | +Returns all environment variables as an object where keys are variable names and values are their corresponding values. |
| 23 | + |
| 24 | +**Return Type**: `Object<string, string>` |
| 25 | + |
| 26 | +**Example**: |
| 27 | +```rust |
| 28 | +use std.env; |
| 29 | + |
| 30 | +let variables = env.vars(); |
| 31 | +// Example output: |
| 32 | +// { |
| 33 | +// "PATH": "/usr/local/bin:/usr/bin", |
| 34 | +// "HOME": "/home/user", |
| 35 | +// "USER": "username" |
| 36 | +// } |
| 37 | +``` |
| 38 | + |
| 39 | +## get_env(name: string) |
| 40 | + |
| 41 | +Gets the value of an environment variable. |
| 42 | + |
| 43 | +**Parameters**: |
| 44 | +- `name`: The name of the environment variable to retrieve |
| 45 | + |
| 46 | +**Return Type**: `string | nil` |
| 47 | + |
| 48 | +**Example**: |
| 49 | +```rust |
| 50 | +use std.env; |
| 51 | + |
| 52 | +let home = env.get_env("HOME"); |
| 53 | +// If HOME is set: "/home/user" |
| 54 | +// If HOME is not set: nil |
| 55 | +``` |
| 56 | + |
| 57 | +## set_env(name: string, value: string) |
| 58 | + |
| 59 | +Sets the value of an environment variable. |
| 60 | + |
| 61 | +**Parameters**: |
| 62 | +- `name`: The name of the environment variable to set |
| 63 | +- `value`: The value to set |
| 64 | + |
| 65 | +**Return Type**: `nil` |
| 66 | + |
| 67 | +**Example**: |
| 68 | +```rust |
| 69 | +use std.env; |
| 70 | + |
| 71 | +env.set_env("MY_VAR", "my_value"); |
| 72 | +let value = env.get_env("MY_VAR") // Returns "my_value" |
| 73 | +``` |
0 commit comments