roc/examples/cli/env.roc
Ayaz 9bf23196a8
Revert stray introduction from #4661
Signed-off-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com>
2022-12-03 12:32:46 -06:00

31 lines
1.0 KiB
Plaintext

app "env"
packages { pf: "cli-platform/main.roc" }
imports [pf.Stdout, pf.Stderr, pf.Env, pf.Task.{ Task }]
provides [main] to pf
main : Task {} []
main =
task =
Env.decode "EDITOR"
|> Task.await (\editor -> Stdout.line "Your favorite editor is \(editor)!")
|> Task.await (\{} -> Env.decode "SHLVL")
|> Task.await
(\lvl ->
when lvl is
1u8 -> Stdout.line "You're running this in a root shell!"
n ->
lvlStr = Num.toStr n
Stdout.line "Your current shell level is \(lvlStr)!")
|> Task.await \{} -> Env.decode "LETTERS"
Task.attempt task \result ->
when result is
Ok letters ->
joinedLetters = Str.joinWith letters " "
Stdout.line "Your favorite letters are: \(joinedLetters)"
Err _ ->
Stderr.line "I couldn't find your favorite letters in the environment variables!"