-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathmain.roc
More file actions
69 lines (59 loc) · 1.48 KB
/
main.roc
File metadata and controls
69 lines (59 loc) · 1.48 KB
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
platform "cli"
requires {} { main! : List Arg.Arg => Result {} [Exit I32 Str]_ }
exposes [
Path,
Arg,
Dir,
Env,
File,
Http,
Stderr,
Stdin,
Stdout,
Tcp,
Url,
Utc,
Sleep,
Cmd,
Tty,
Locale,
Sqlite,
Random,
]
packages {}
imports []
provides [main_for_host!]
import Arg
import Stderr
import InternalArg
main_for_host! : List InternalArg.ArgToAndFromHost => I32
main_for_host! = |raw_args|
args =
raw_args
|> List.map(InternalArg.to_os_raw)
|> List.map(Arg.from_os_raw)
when main!(args) is
Ok({}) -> 0
Err(Exit(code, msg)) ->
if Str.is_empty(msg) then
code
else
_ = Stderr.line!(msg)
code
Err(err) ->
err_str = Inspect.to_str(err)
clean_err_str =
# Inspect adds parentheses around errors, which are unnecessary here.
if Str.starts_with(err_str, "(") and Str.ends_with(err_str, ")") then
err_str
|> Str.replace_first("(", "")
|> Str.replace_last(")", "")
else
err_str
help_msg =
"""
Program exited with error:
❌ ${clean_err_str}
"""
_ = Stderr.line!(help_msg)
1