cli-extras-0.1.0.0: Miscellaneous utilities for building and working with command line interfaces

Safe HaskellNone
LanguageHaskell2010

Cli.Extras

Description

Package for writing great CLI apps.

See Demo.hs for an example

This package should eventually be made its own library.

Synopsis

Documentation

type CliThrow e m = MonadError e m Source #

newtype CliT e m a Source #

Constructors

CliT 
Instances
Monad m => MonadError e (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

throwError :: e -> CliT e m a #

catchError :: CliT e m a -> (e -> CliT e m a) -> CliT e m a #

Monad m => MonadLog Output (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

logMessageFree :: (forall n. Monoid n => (Output -> n) -> n) -> CliT e m () #

MonadTrans (CliT e) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

lift :: Monad m => m a -> CliT e m a #

Monad m => Monad (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

(>>=) :: CliT e m a -> (a -> CliT e m b) -> CliT e m b #

(>>) :: CliT e m a -> CliT e m b -> CliT e m b #

return :: a -> CliT e m a #

fail :: String -> CliT e m a #

Functor m => Functor (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

fmap :: (a -> b) -> CliT e m a -> CliT e m b #

(<$) :: a -> CliT e m b -> CliT e m a #

MonadFail m => MonadFail (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

fail :: String -> CliT e m a #

Monad m => Applicative (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

pure :: a -> CliT e m a #

(<*>) :: CliT e m (a -> b) -> CliT e m a -> CliT e m b #

liftA2 :: (a -> b -> c) -> CliT e m a -> CliT e m b -> CliT e m c #

(*>) :: CliT e m a -> CliT e m b -> CliT e m b #

(<*) :: CliT e m a -> CliT e m b -> CliT e m a #

MonadIO m => MonadIO (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

liftIO :: IO a -> CliT e m a #

MonadThrow m => MonadThrow (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

throwM :: Exception e0 => e0 -> CliT e m a #

MonadCatch m => MonadCatch (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

catch :: Exception e0 => CliT e m a -> (e0 -> CliT e m a) -> CliT e m a #

MonadMask m => MonadMask (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

mask :: ((forall a. CliT e m a -> CliT e m a) -> CliT e m b) -> CliT e m b #

uninterruptibleMask :: ((forall a. CliT e m a -> CliT e m a) -> CliT e m b) -> CliT e m b #

generalBracket :: CliT e m a -> (a -> ExitCase b -> CliT e m c) -> (a -> CliT e m b) -> CliT e m (b, c) #

Monad m => HasCliConfig (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

runCli :: MonadIO m => CliConfig -> CliT e m a -> m (Either e a) Source #

class Monad m => HasCliConfig m Source #

Minimal complete definition

getCliConfig

Instances
HasCliConfig m => HasCliConfig (ExceptT e m) Source # 
Instance details

Defined in Cli.Extras.Types

(Monoid w, HasCliConfig m) => HasCliConfig (WriterT w m) Source # 
Instance details

Defined in Cli.Extras.Types

HasCliConfig m => HasCliConfig (StateT s m) Source # 
Instance details

Defined in Cli.Extras.Types

HasCliConfig m => HasCliConfig (ReaderT r m) Source # 
Instance details

Defined in Cli.Extras.Types

Monad m => HasCliConfig (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

HasCliConfig m => HasCliConfig (SubExceptT e eSub m) Source # 
Instance details

Defined in Cli.Extras.Types

data Output Source #

Instances
Eq Output Source # 
Instance details

Defined in Cli.Extras.Types

Methods

(==) :: Output -> Output -> Bool #

(/=) :: Output -> Output -> Bool #

Ord Output Source # 
Instance details

Defined in Cli.Extras.Types

Show Output Source # 
Instance details

Defined in Cli.Extras.Types

Monad m => MonadLog Output (CliT e m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

logMessageFree :: (forall n. Monoid n => (Output -> n) -> n) -> CliT e m () #

MonadFail m => MonadFail (LoggingT Output m) Source # 
Instance details

Defined in Cli.Extras.Types

Methods

fail :: String -> LoggingT Output m a #

withSpinner :: (MonadIO m, MonadMask m, CliLog m, HasCliConfig m) => Text -> m a -> m a Source #

Run an action with a CLI spinner.

withSpinnerNoTrail :: (MonadIO m, MonadMask m, CliLog m, HasCliConfig m) => Text -> m a -> m a Source #

A spinner that leaves no trail after a successful run.

Use if you wish the spinner to be ephemerally visible to the user.

The 'no trail' property automatically carries over to sub-spinners (in that they won't leave a trail either).

withSpinner' Source #

Arguments

:: (MonadIO m, MonadMask m, CliLog m, HasCliConfig m) 
=> Text 
-> Maybe (a -> Text)

Leave an optional trail with the given message creator

-> m a 
-> m a 

Advanced version that controls the display and content of the trail message.

class AsUnstructuredError e where Source #

Indicates unstructured errors form one variant (or conceptual projection) of the error type.

Shouldn't really use this, but who has time to clean up that much!

putLog :: CliLog m => Severity -> Text -> m () Source #

Log a message to the console.

Logs safely even if there are ongoing spinners.

failWith :: (CliThrow e m, AsUnstructuredError e) => Text -> m a Source #

Like `putLog Alert` but also abrupts the program.

withExitFailMessage :: (CliLog m, MonadCatch m) => Text -> m a -> m a Source #

Intercept ExitFailure exceptions and log the given alert before exiting.

This is useful when you want to provide contextual information to a deeper failure.

data Severity #

Classes of severity for log messages. These have been chosen to match syslog severity levels

Constructors

Emergency

System is unusable. By syslog convention, this level should not be used by applications.

Alert

Should be corrected immediately.

Critical

Critical conditions.

Error

Error conditions.

Warning

May indicate that an error will occur if action is not taken.

Notice

Events that are unusual, but not error conditions.

Informational

Normal operational messages that require no action.

Debug

Information useful to developers for debugging the application.

Instances
Bounded Severity 
Instance details

Defined in Control.Monad.Log

Enum Severity 
Instance details

Defined in Control.Monad.Log

Eq Severity 
Instance details

Defined in Control.Monad.Log

Ord Severity 
Instance details

Defined in Control.Monad.Log

Read Severity 
Instance details

Defined in Control.Monad.Log

Show Severity 
Instance details

Defined in Control.Monad.Log

Pretty Severity 
Instance details

Defined in Control.Monad.Log

Methods

pretty :: Severity -> Doc ann #

prettyList :: [Severity] -> Doc ann #

class AsProcessFailure e where Source #

Indicates arbitrary process failures form one variant (or conceptual projection) of the error type.

callCommand :: (MonadIO m, CliLog m) => String -> m () Source #

Like callCommand but also logs (debug) the command being run

callProcess :: (MonadIO m, CliLog m) => String -> [String] -> m () Source #

Like callProcess but also logs (debug) the process being run

callProcessAndLogOutput :: (MonadIO m, CliLog m, CliThrow e m, AsProcessFailure e, MonadFail m) => (Severity, Severity) -> ProcessSpec -> m () Source #

Like callProcess but logs the combined output (stdout and stderr) with the corresponding severity.

Usually this function is called as `callProcessAndLogOutput (Debug, Error)`. However some processes are known to spit out diagnostic or informative messages in stderr, in which case it is advisable to call it with a non-Error severity for stderr, like `callProcessAndLogOutput (Debug, Debug)`.

createProcess_ :: (MonadIO m, CliLog m) => String -> ProcessSpec -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) Source #

Like createProcess_ but also logs (debug) the process being run

readProcessAndLogOutput :: (MonadIO m, CliLog m, CliThrow e m, AsProcessFailure e, MonadFail m) => (Severity, Severity) -> ProcessSpec -> m Text Source #

Like readProcess but logs the combined output (stdout and stderr) with the corresponding severity.

Usually this function is called as `callProcessAndLogOutput (Debug, Error)`. However some processes are known to spit out diagnostic or informative messages in stderr, in which case it is advisable to call it with a non-Error severity for stderr, like `callProcessAndLogOutput (Debug, Debug)`.

reconstructCommand :: CmdSpec -> Text Source #

Pretty print a CmdSpec