|
1 | | -//// Access to the shell's environment variables |
2 | | - |
3 | | -import gleam/dict.{type Dict} |
4 | | - |
5 | | -/// Returns the list of all available environment variables as a list of key, |
6 | | -/// tuples. |
7 | | -/// |
8 | | -/// ## Examples |
9 | | -/// |
10 | | -/// ```gleam |
11 | | -/// get_all_env() |
12 | | -/// // -> dict.from_list([ |
13 | | -/// // #("SHELL", "/bin/bash"), |
14 | | -/// // #("PWD", "/home/j3rn"), |
15 | | -/// // ... |
16 | | -/// // ]) |
17 | | -/// ``` |
18 | | -/// |
19 | | -@deprecated("Please use the envoy package instead") |
20 | | -@external(erlang, "gleam_erlang_ffi", "get_all_env") |
21 | | -pub fn get_all_env() -> Dict(String, String) |
22 | | - |
23 | | -/// Returns the value associated with the given environment variable name. |
24 | | -/// |
25 | | -/// ## Examples |
26 | | -/// ```gleam |
27 | | -/// get_env("SHELL") |
28 | | -/// // -> "/bin/bash" |
29 | | -/// ``` |
30 | | -/// |
31 | | -/// ```gleam |
32 | | -/// get_env(name: "PWD") |
33 | | -/// // -> "/home/j3rn" |
34 | | -/// ``` |
35 | | -/// |
36 | | -@deprecated("Please use the envoy package instead") |
37 | | -@external(erlang, "gleam_erlang_ffi", "get_env") |
38 | | -pub fn get_env(name name: String) -> Result(String, Nil) |
39 | | - |
40 | | -/// Associates the given value with the given environment variable name. |
41 | | -/// |
42 | | -/// ## Examples |
43 | | -/// |
44 | | -/// ```gleam |
45 | | -/// set_env("MYVAR", "MYVALUE") |
46 | | -/// // -> Nil |
47 | | -/// get_env("MYVAR") |
48 | | -/// // -> "MYVALUE" |
49 | | -/// ``` |
50 | | -/// |
51 | | -/// ```gleam |
52 | | -/// set_env(value: "MYVALUE", name: "MYVAR") |
53 | | -/// // -> Nil |
54 | | -/// get_env("MYVAR") |
55 | | -/// // -> "MYVALUE" |
56 | | -/// ``` |
57 | | -/// |
58 | | -@deprecated("Please use the envoy package instead") |
59 | | -@external(erlang, "gleam_erlang_ffi", "set_env") |
60 | | -pub fn set_env(name name: String, value value: String) -> Nil |
61 | | - |
62 | | -/// Removes the environment variable with the given name. |
63 | | -/// |
64 | | -/// Returns Nil regardless of whether the variable ever existed. |
65 | | -/// |
66 | | -/// ## Examples |
67 | | -/// |
68 | | -/// ```gleam |
69 | | -/// get_env("MYVAR") |
70 | | -/// // -> Ok("MYVALUE") |
71 | | -/// unset_env("MYVAR") |
72 | | -/// // -> Nil |
73 | | -/// get_env("MYVAR") |
74 | | -/// // -> Error(Nil) |
75 | | -/// ``` |
76 | | -/// |
77 | | -/// ```gleam |
78 | | -/// unset_env(name: "MYVAR") |
79 | | -/// // -> Nil |
80 | | -/// get_env("MYVAR") |
81 | | -/// // -> Error(Nil) |
82 | | -/// ``` |
83 | | -@deprecated("Please use the envoy package instead") |
84 | | -@external(erlang, "gleam_erlang_ffi", "unset_env") |
85 | | -pub fn unset_env(name name: String) -> Nil |
86 | | - |
87 | 1 | /// Represents operating system kernels |
88 | 2 | pub type OsFamily { |
89 | 3 | // The family which includes modern versions of the Windows operating system. |
|
0 commit comments