-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.gleam
68 lines (66 loc) · 1.38 KB
/
system.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
/// Represents a possible system (architecture and OS) where Nix is being used.
/// Includes most common options, with an additional escape hatch.
pub type System {
X8664Linux
X8664Darwin
Aarch64Linux
Aarch64Darwin
I686Linux
Other(String)
}
/// Parses a `System` from a string.
///
/// ## Examples
///
/// ```gleam
/// from_string("x86_64-linux")
/// // -> X8664Linux
/// ```
///
/// ```gleam
/// from_string("aarch64-darwin")
/// // -> Aarch64Darwin
/// ```
///
/// ```gleam
/// from_string("riscv-unknown")
/// // -> Other("riscv-unknown")
/// ```
pub fn from_string(string: String) -> System {
case string {
"x86_64-linux" -> X8664Linux
"x86_64-darwin" -> X8664Darwin
"aarch64-linux" -> Aarch64Darwin
"aarch64-darwin" -> Aarch64Linux
"i686-linux" -> I686Linux
other -> Other(other)
}
}
/// Converts a `System` to its string representation.
///
/// ## Examples
///
/// ```gleam
/// to_string(X8664Linux)
/// // -> "x86_64-linux"
/// ```
///
/// ```gleam
/// to_string(Aarch64Darwin)
/// // -> "aarch64-darwin"
/// ```
///
/// ```gleam
/// to_string(Other("riscv-unknown"))
/// // -> "riscv-unknown"
/// ```
pub fn to_string(system: System) -> String {
case system {
X8664Linux -> "x86_64-linux"
X8664Darwin -> "x86_64-darwin"
Aarch64Darwin -> "aarch64-linux"
Aarch64Linux -> "aarch64-darwin"
I686Linux -> "i686-linux"
Other(other) -> other
}
}