Skip to content

Commit 278b480

Browse files
committed
Add command and variable substitution examples.
1 parent 24cf3a7 commit 278b480

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

examples/CommandSubstitution.purs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Example.CommandSubstitution (main) where
2+
3+
import Prelude
4+
5+
import Data.Maybe (maybe)
6+
import Dotenv (loadContents) as Dotenv
7+
import Effect (Effect)
8+
import Effect.Aff (launchAff_, throwError)
9+
import Effect.Class (liftEffect)
10+
import Effect.Console (log)
11+
import Effect.Exception (error)
12+
import Node.Process (lookupEnv)
13+
14+
main :: Effect Unit
15+
main = launchAff_ do
16+
Dotenv.loadContents "GREETING=Hello, $(whoami)!" -- Normally you'll use `loadFile` instead.
17+
liftEffect do
18+
greeting <- lookupEnv "GREETING"
19+
maybe (throwError $ error $ "Couldn't find GREETING!") log greeting

examples/VariableSubstitution.purs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Example.VariableSubstitution (main) where
2+
3+
import Prelude
4+
5+
import Data.Maybe (maybe)
6+
import Dotenv (loadContents) as Dotenv
7+
import Effect (Effect)
8+
import Effect.Aff (launchAff_, throwError)
9+
import Effect.Class (liftEffect)
10+
import Effect.Console (log)
11+
import Effect.Exception (error)
12+
import Node.Process (lookupEnv)
13+
14+
main :: Effect Unit
15+
main = launchAff_ do
16+
Dotenv.loadContents "WHO=World\nGREETING=Hello, ${WHO}!" -- Normally you'll use `loadFile` instead.
17+
liftEffect do
18+
greeting <- lookupEnv "GREETING"
19+
maybe (throwError $ error $ "Couldn't find GREETING!") log greeting

0 commit comments

Comments
 (0)