on decrease-android-validity help sign in
52 lines 1.9 kB history raw
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4module Obelisk.CliApp.Demo where
6import Control.Concurrent (threadDelay)
7import Control.Monad.IO.Class
8import Data.Semigroup ((<>))
9import qualified Data.Text as T
10import System.Process (proc)
12import Control.Monad.Catch (MonadMask)
14import Obelisk.CliApp
16cliDemo
17 :: ( MonadIO m, MonadMask m
18 , CliLog m, HasCliConfig e m, CliThrow e m, AsProcessFailure e, AsUnstructuredError e)
19 => m ()
20cliDemo = withSpinner "CLI Demo" $ do
21 putLog Notice "This demo will showcase the CLI library functionality"
22 _ <- withSpinner' "Searching long for something" (Just $ \c -> "Discovered " <> T.pack (show c) <> " objects") $ do
23 delay
24 withSpinner "Nested task" $ do
25 delay
26 putLog Notice "In nested task"
27 -- This is a 'no trail' spinner that won't leave a trail (even its sub spinners)
28 withSpinnerNoTrail "In between, doing something temporary" $ do
29 withSpinner "Runnning something deep inside" $ do
30 delay
31 putLog Notice "You can still log from inside no-trail spinners"
32 delay
33 delay
34 putLog Error "Top nested task finished"
35 delay
36 putLog Error "Some user error while spinning"
37 delay
38 putLog Notice "This is some info mesage"
39 putLog Warning "And now a warning as well"
40 delay
41 return (42 :: Integer)
42 putLog Notice "Now we start a 2nd spinner, run a couple of process, the last of which fails:"
43 withSpinner "Looking around" $ do
44 delay
45 output <- readProcessAndLogStderr Notice $ proc "ls" ["-l", "/"]
46 putLog Notice $ "Output was: " <> output
47 delay
48 callProcessAndLogOutput (Notice, Error) $ proc "ls" ["-l", "/does-not-exist"]
49 delay
50 failWith "Something dangerous happened"
51 where
52 delay = liftIO $ threadDelay 1000000