-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
os.gleam
95 lines (88 loc) 路 2.25 KB
/
os.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//// Access to the shell's environment variables
import gleam/map.{Map}
/// Returns the list of all available environment variables as a list of key,
/// tuples.
///
/// ## Examples
///
/// > get_all_env()
/// map.from_list([
/// #("SHELL", "/bin/bash"),
/// #("PWD", "/home/j3rn"),
/// ...
/// ])
///
pub external fn get_all_env() -> Map(String, String) =
"gleam_erlang_ffi" "get_all_env"
/// Returns the value associated with the given environment variable name.
///
/// ## Examples
///
/// > get_env("SHELL")
/// "/bin/bash"
///
/// > get_env(name: "PWD")
/// "/home/j3rn"
///
pub external fn get_env(name: String) -> Result(String, Nil) =
"gleam_erlang_ffi" "get_env"
/// Associates the given value with the given environment variable name.
///
/// ## Examples
///
/// > set_env("MYVAR", "MYVALUE")
/// Nil
/// > get_env("MYVAR")
/// "MYVALUE"
///
/// > set_env(value: "MYVALUE", name: "MYVAR")
/// Nil
///
pub external fn set_env(name: String, value: String) -> Nil =
"gleam_erlang_ffi" "set_env"
/// Removes the environment variable with the given name.
///
/// Returns Nil regardless of whether the variable ever existed.
///
/// ## Examples
///
/// > get_env("MYVAR")
/// Ok("MYVALUE")
/// > unset_env("MYVAR")
/// Nil
/// > get_env("MYVAR")
/// Error(Nil)
///
/// > unset_env(name: "MYVAR")
/// Nil
///
pub external fn unset_env(name: String) -> Nil =
"gleam_erlang_ffi" "unset_env"
/// Represents operating system kernels
pub type OsFamily {
// The family which includes modern versions of the Windows operating system.
WindowsNt
// The family of operating systems based on the open source Linux kernel.
Linux
// The family of Apple operating systems such as macOS and iOS.
Darwin
// The family of operating systems based on the FreeBSD kernel.
FreeBsd
// An operating system kernel other than Linux, Darwin, FreeBSD, or NT.
Other(String)
}
/// Returns the kernel of the host operating system.
///
/// Unknown kernels are reported as `Other(String)`; e.g. `Other("sunos")`.
///
/// ## Examples
///
/// > family()
/// Linux
/// > family()
/// Darwin
/// > family()
/// Other("sunos")
///
pub external fn family() -> OsFamily =
"gleam_erlang_ffi" "os_family"