unison-cli-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Cli.Monad

Description

The main CLI monad.

Synopsis

Cli monad

data Cli a Source #

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.

Instances

Instances details
MonadIO Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

liftIO :: IO a -> Cli a #

Applicative Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

pure :: a -> Cli a #

(<*>) :: Cli (a -> b) -> Cli a -> Cli b #

liftA2 :: (a -> b -> c) -> Cli a -> Cli b -> Cli c #

(*>) :: Cli a -> Cli b -> Cli b #

(<*) :: Cli a -> Cli b -> Cli a #

Functor Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

fmap :: (a -> b) -> Cli a -> Cli b #

(<$) :: a -> Cli b -> Cli a #

Monad Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

(>>=) :: Cli a -> (a -> Cli b) -> Cli b #

(>>) :: Cli a -> Cli b -> Cli b #

return :: a -> Cli a #

MonadReader Env Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

ask :: Cli Env #

local :: (Env -> Env) -> Cli a -> Cli a #

reader :: (Env -> a) -> Cli a #

MonadState LoopState Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

get :: Cli LoopState #

put :: LoopState -> Cli () #

state :: (LoopState -> (a, LoopState)) -> Cli a #

data ReturnType a Source #

What a Cli action returns: a value, an instruction to continue processing input, or an instruction to stop processing input.

Constructors

Success a 
Continue 
HaltRepl 

Instances

Instances details
Show a => Show (ReturnType a) Source # 
Instance details

Defined in Unison.Cli.Monad

Eq a => Eq (ReturnType a) Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

(==) :: 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

data Env Source #

The command-line app monad environment.

Get the environment with ask.

Constructors

Env 

Fields

Instances

Instances details
Generic Env Source # 
Instance details

Defined in Unison.Cli.Monad

Associated Types

type Rep Env :: Type -> Type #

Methods

from :: Env -> Rep Env x #

to :: Rep Env x -> Env #

MonadReader Env Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

ask :: Cli Env #

local :: (Env -> Env) -> Cli a -> Cli a #

reader :: (Env -> a) -> Cli a #

type Rep Env Source # 
Instance details

Defined in Unison.Cli.Monad

type Rep Env = D1 ('MetaData "Env" "Unison.Cli.Monad" "unison-cli-0.0.0-B9QON8ivVlfDVnczaEfnsV" 'False) (C1 ('MetaCons "Env" 'PrefixI 'True) (((S1 ('MetaSel ('Just "authHTTPClient") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 AuthenticatedHttpClient) :*: (S1 ('MetaSel ('Just "codebase") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Codebase IO Symbol Ann)) :*: S1 ('MetaSel ('Just "credentialManager") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CredentialManager))) :*: ((S1 ('MetaSel ('Just "generateUniqueName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (IO UniqueName)) :*: S1 ('MetaSel ('Just "loadSource") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SourceName -> IO LoadSourceResult))) :*: (S1 ('MetaSel ('Just "writeSource") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SourceName -> Text -> IO ())) :*: S1 ('MetaSel ('Just "notify") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Output -> IO ()))))) :*: ((S1 ('MetaSel ('Just "notifyNumbered") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NumberedOutput -> IO NumberedArgs)) :*: (S1 ('MetaSel ('Just "runtime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Runtime Symbol)) :*: S1 ('MetaSel ('Just "sandboxedRuntime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Runtime Symbol)))) :*: ((S1 ('MetaSel ('Just "nativeRuntime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Runtime Symbol)) :*: S1 ('MetaSel ('Just "serverBaseUrl") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe BaseUrl))) :*: (S1 ('MetaSel ('Just "ucmVersion") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UCMVersion) :*: S1 ('MetaSel ('Just "isTranscriptTest") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))))

Immutable state

data LoopState Source #

The command-line app monad mutable state.

There's an additional pseudo "currentPath" field lens, for convenience.

Instances

Instances details
Generic LoopState Source # 
Instance details

Defined in Unison.Cli.Monad

Associated Types

type Rep LoopState :: Type -> Type #

MonadState LoopState Cli Source # 
Instance details

Defined in Unison.Cli.Monad

Methods

get :: Cli LoopState #

put :: LoopState -> Cli () #

state :: (LoopState -> (a, LoopState)) -> Cli a #

type Rep LoopState Source # 
Instance details

Defined in Unison.Cli.Monad

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 ->
  ...

with_ :: (forall x. IO x -> IO x) -> Cli a -> Cli a Source #

A variant of with for actions that don't acquire a resource (like bracket_).

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.

haltRepl :: Cli a Source #

Stop processing inputs from the user.

Changing the current directory

popd :: Cli Bool Source #

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

setNumberedArgs :: NumberedArgs -> Cli () Source #

Updates the numbered args, but only if the new args are non-empty.

Debug-timing actions

time :: String -> Cli a -> Cli a Source #

Time an action.

Running transactions

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

Misc types