Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The main CLI monad.
Synopsis
- data Cli a
- data ReturnType a
- type SourceName = Text
- runCli :: Env -> LoopState -> Cli a -> IO (ReturnType a, LoopState)
- data Env = Env {
- authHTTPClient :: AuthenticatedHttpClient
- codebase :: Codebase IO Symbol Ann
- credentialManager :: CredentialManager
- generateUniqueName :: IO UniqueName
- loadSource :: SourceName -> IO LoadSourceResult
- writeSource :: SourceName -> Text -> Bool -> IO ()
- notify :: Output -> IO ()
- notifyNumbered :: NumberedOutput -> IO NumberedArgs
- runtime :: Runtime Symbol
- sandboxedRuntime :: Runtime Symbol
- nativeRuntime :: Runtime Symbol
- serverBaseUrl :: Maybe BaseUrl
- ucmVersion :: UCMVersion
- isTranscriptTest :: Bool
- data LoopState = LoopState {
- projectPathStack :: NonEmpty ProjectPathIds
- latestFile :: Maybe (FilePath, Bool)
- latestTypecheckedFile :: Maybe (Either (UnisonFile Symbol Ann) (TypecheckedUnisonFile Symbol Ann))
- lastInput :: Maybe Input
- numberedArgs :: NumberedArgs
- lastRunResult :: Maybe (Term Symbol Ann, Type Symbol Ann, TypecheckedUnisonFile Symbol Ann)
- loopState0 :: ProjectPathIds -> LoopState
- getProjectPathIds :: Cli ProjectPathIds
- ioE :: IO (Either e a) -> (e -> Cli a) -> Cli a
- with :: (forall x. (a -> IO x) -> IO x) -> (a -> Cli b) -> Cli b
- with_ :: (forall x. IO x -> IO x) -> Cli a -> Cli a
- withE :: (forall x. (a -> IO x) -> IO (Either e x)) -> (Either e a -> Cli b) -> Cli b
- label :: forall a. ((forall void. a -> Cli void) -> Cli a) -> Cli a
- labelE :: ((forall void. a -> Cli void) -> Cli b) -> Cli (Either a b)
- returnEarly :: Output -> Cli a
- returnEarlyWithoutOutput :: Cli a
- haltRepl :: Cli a
- cd :: Absolute -> Cli ()
- popd :: Cli Bool
- switchProject :: ProjectAndBranch ProjectId ProjectBranchId -> Cli ()
- respond :: Output -> Cli ()
- respondNumbered :: NumberedOutput -> Cli ()
- withRespondRegion :: ((Output -> Cli ()) -> Cli a) -> Cli a
- setNumberedArgs :: NumberedArgs -> Cli ()
- time :: String -> Cli a -> Cli a
- runTransaction :: Transaction a -> Cli a
- runTransactionWithRollback :: ((forall void. Output -> Transaction void) -> Transaction a) -> Cli a
- runTransactionWithRollback2 :: ((forall void. a -> Transaction void) -> Transaction a) -> Cli a
- setMostRecentProjectPath :: ProjectPathIds -> Cli ()
- data LoadSourceResult
Cli monad
The main command-line app monad.
- It is a reader monad of
Env
. - It is a state monad of
LoopState
. - It is a short-circuiting monad: a
Cli
computation can short-circuit with success or failure in a delimited scope. - It is a resource monad: resources can be acquired in callback-style.
- It is an IO monad: you can do IO things, but throwing synchronous exceptions is discouraged. Use the built-in short-circuiting mechanism instead.
data ReturnType a Source #
What a Cli action returns: a value, an instruction to continue processing input, or an instruction to stop processing input.
Instances
Show a => Show (ReturnType a) Source # | |
Defined in Unison.Cli.Monad showsPrec :: Int -> ReturnType a -> ShowS # show :: ReturnType a -> String # showList :: [ReturnType a] -> ShowS # | |
Eq a => Eq (ReturnType a) Source # | |
Defined in Unison.Cli.Monad (==) :: ReturnType a -> ReturnType a -> Bool # (/=) :: ReturnType a -> ReturnType a -> Bool # |
type SourceName = Text Source #
Name used for a source-file/source buffer
runCli :: Env -> LoopState -> Cli a -> IO (ReturnType a, LoopState) Source #
Run a Cli
action down to IO
.
Envronment
The command-line app monad environment.
Get the environment with ask
.
Env | |
|
Instances
Immutable state
The command-line app monad mutable state.
There's an additional pseudo "currentPath"
field lens, for convenience.
Instances
loopState0 :: ProjectPathIds -> LoopState Source #
Create an initial loop state given a root branch and the current path.
Lifting IO actions
ioE :: IO (Either e a) -> (e -> Cli a) -> Cli a Source #
Lift an action of type IO (Either e a)
, given a continuation for e
.
Acquiring resources
with :: (forall x. (a -> IO x) -> IO x) -> (a -> Cli b) -> Cli b Source #
Wrap a continuation with Cli
.
Useful for resource acquisition:
with (bracket create destroy) \resource -> ...
withE :: (forall x. (a -> IO x) -> IO (Either e x)) -> (Either e a -> Cli b) -> Cli b Source #
A variant of with
for the variant of bracketing function that may return a Left rather than call the provided
continuation.
Short-circuiting
label :: forall a. ((forall void. a -> Cli void) -> Cli a) -> Cli a Source #
Create a label that can be jumped to.
x <- label \j0 -> do ... label \j1 -> do ... j0 someValue ... -- We don't get here ... -- We don't get here -- x is bound to someValue
labelE :: ((forall void. a -> Cli void) -> Cli b) -> Cli (Either a b) Source #
A variant of label
for the common case that early-return values are tagged with a Left.
returnEarly :: Output -> Cli a Source #
Short-circuit the processing of the current input.
returnEarlyWithoutOutput :: Cli a Source #
Variant of returnEarly
that doesn't take a final output message.
Changing the current directory
Pop the latest path off the stack, if it's not the only path in the stack.
Returns whether anything was popped.
Communicating output to the user
respondNumbered :: NumberedOutput -> Cli () Source #
withRespondRegion :: ((Output -> Cli ()) -> Cli a) -> Cli a Source #
Perform a Cli action with access to a console region, which is closed upon completion.
(In transcripts, this just outputs messages as normal).
setNumberedArgs :: NumberedArgs -> Cli () Source #
Updates the numbered args, but only if the new args are non-empty.
Debug-timing actions
Running transactions
runTransaction :: Transaction a -> Cli a Source #
runTransactionWithRollback :: ((forall void. Output -> Transaction void) -> Transaction a) -> Cli a Source #
Run a transaction that can abort early with an output message. todo: rename to runTransactionWithReturnEarly
runTransactionWithRollback2 :: ((forall void. a -> Transaction void) -> Transaction a) -> Cli a Source #
Run a transaction that can abort early. todo: rename to runTransactionWithRollback
Internal
setMostRecentProjectPath :: ProjectPathIds -> Cli () Source #
Misc types
data LoadSourceResult Source #
The result of calling $sel:loadSource:Env
.