Safe Haskell | None |
---|---|
Language | Haskell2010 |
The main Zifter
module.
In most cases this should be the only module you import to start writing a
zift.hs
script. You will most likely want to import the appropriate
modules from the 'zifter-*' companion packages.
- ziftWith :: ZiftScript () -> IO ()
- ziftWithSetup :: ZiftSetup -> IO ()
- preprocessor :: Zift () -> ZiftScript ()
- prechecker :: Zift () -> ZiftScript ()
- checker :: Zift () -> ZiftScript ()
- ziftP :: [Zift ()] -> Zift ()
- mapZ :: (a -> Zift b) -> [a] -> Zift [b]
- mapZ_ :: (a -> Zift b) -> [a] -> Zift ()
- forZ :: [a] -> (a -> Zift b) -> Zift [b]
- forZ_ :: [a] -> (a -> Zift b) -> Zift ()
- recursiveZift :: ZiftScript ()
- data ZiftScript a
- renderZiftSetup :: ZiftScript a -> IO ZiftSetup
- data Zift a
- getRootDir :: Zift (Path Abs Dir)
- getTmpDir :: Zift (Path Abs Dir)
- getSettings :: Zift Settings
- getSetting :: (Settings -> a) -> Zift a
- data Settings = Settings {}
- printZift :: String -> Zift ()
- printZiftMessage :: String -> Zift ()
- printPreprocessingDone :: String -> Zift ()
- printPreprocessingError :: String -> Zift ()
- printWithColors :: [SGR] -> String -> Zift ()
- runZiftAuto :: (ZiftContext -> Zift ()) -> Settings -> IO ()
- runZift :: ZiftContext -> Zift a -> IO (ZiftResult a)
- ziftRunner :: ZiftContext -> TMVar () -> Zift a -> IO (ZiftResult a)
- outputPrinter :: OutputSets -> TChan ZiftToken -> TMVar () -> IO ()
- data LinearState
- prettyToken :: ZiftToken -> String
- prettyState :: LinearState -> String
- processToken :: LinearState -> ZiftToken -> Maybe (LinearState, Buf)
- addState :: LinearState -> ZiftToken -> Maybe LinearState
- flushState :: LinearState -> (LinearState, Buf)
- data Buf
- pruneState :: LinearState -> LinearState
- flushStateAll :: LinearState -> Buf
Documentation
ziftWith :: ZiftScript () -> IO () Source #
Run a ZiftScript
to create the ZiftSetup
, and then use ziftWithSetup
ziftWith = renderZiftSetup >=> ziftWithSetup
ziftWithSetup :: ZiftSetup -> IO () Source #
Build a zifter using a ZiftSetup
.
A zifter has the capabilities that you would expect from a 'zift.hs' file:
zift.hs run
: Run thezift.hs
script as a pre-commit hook.zift.hs preprocess
: Run the preprocessorzift.hs precheck
: Run the precheckerzift.hs check
: Run the checkerzift.hs install
: Install thezift.hs
script as a pre-commit hook.
Defining your own zift scripts
preprocessor :: Zift () -> ZiftScript () Source #
Add a given zift action as a preprocessor.
prechecker :: Zift () -> ZiftScript () Source #
Add a given zift action as a prechecker.
checker :: Zift () -> ZiftScript () Source #
Add a given zift action as a checker.
ziftP :: [Zift ()] -> Zift () Source #
Declare a given list of Zift
actions to be execute in parallel.
mapZ :: (a -> Zift b) -> [a] -> Zift [b] Source #
Like mapA
, but specialised to Zift
and '[]', and ensures that the
output of actions is printed in the right order, even if they are
executed in an arbitrary order.
mapZ_ :: (a -> Zift b) -> [a] -> Zift () Source #
Like mapA_
, but specialised to Zift
and '[]', and ensures that the
output of actions is printed in the right order, even if they are
executed in an arbitrary order.
forZ :: [a] -> (a -> Zift b) -> Zift [b] Source #
Like for
, but specialised to Zift
and '[]', and ensures that the
output of actions is printed in the right order, even if they are
executed in an arbitrary order.
forZ_ :: [a] -> (a -> Zift b) -> Zift () Source #
Like for_
, but specialised to Zift
and '[]', and ensures that the output of
actions is printed in the right order.
recursiveZift :: ZiftScript () Source #
Recursively call each zift.hs
script in the directories below the
directory of the currently executing zift.hs
script.
Only the topmost zift.hs
script in each directory is executed.
This means that, to execute all zift.hs
scripts recursively, each of those
zift.hs
scripts must also have a recursiveZift
declaration.
data ZiftScript a Source #
Monad ZiftScript Source # | |
Functor ZiftScript Source # | |
Applicative ZiftScript Source # | |
Generic (ZiftScript a) Source # | |
type Rep (ZiftScript a) Source # | |
renderZiftSetup :: ZiftScript a -> IO ZiftSetup Source #
Defining your own zift actions
Monad Zift Source # |
|
Functor Zift Source # | |
MonadFail Zift Source # | A To make a Zift action fail, you can use the The implementation uses the given string as the message that is shown at the very end of the run. |
Applicative Zift Source # |
The implementation automatically parallelises the arguments of the
|
MonadIO Zift Source # | Any IO action can be part of a This is the most important instance for the end user. liftIO :: IO a -> Zift a allows embedding arbitrary IO actions inside a The implementation also ensures that exceptions are caught. |
MonadThrow Zift Source # | |
Monoid a => Monoid (Zift a) Source # | |
getRootDir :: Zift (Path Abs Dir) Source #
Get the root directory of the zift.hs
script that is being executed.
getTmpDir :: Zift (Path Abs Dir) Source #
Get the temporary directory of the zift.hs
script that is being executed.
To persist any state between runs, use this directory.
getSetting :: (Settings -> a) -> Zift a Source #
Get a single setting
Console outputs of a zift action
Because Zift
actions are automatically parallelised, it is important
that they do not arbitrarily output data to the console.
Instead, you should use these functions to output to the console.
The ziftWith
and ziftWithSetup
functions will take care of ensuring
that the output appears linear.
printZiftMessage :: String -> Zift () Source #
Print a message (with a newline appended to the end), in the standard zift script color. This is the function that the zift script uses to output information about the stages of the zift script run.
printPreprocessingDone :: String -> Zift () Source #
Print a message (with a newline appended to the end) that signifies that a part of the processing is now done.
Example:
doThingZift :: Zift () doThingZift = do doThing printProcessingDone "doThing completed successfully."
printPreprocessingError :: String -> Zift () Source #
Print a message (with a newline appended to the end) that signifies that a part of the processing failed. This message will not cause the zift script run to fail.
Example:
doDangerousThing :: Zift () doDangerousThing = do errOrResult <- doThing case errOrResult of Left err -> printPreprocessingError $ unwords ["doThing failed with error:", err] fail "doThing failed." Right result -> do printPreprocessingDone unwords ["doThing succeeded with result:", result]
printWithColors :: [SGR] -> String -> Zift () Source #
Print a message (with a newline appended to the end) with custom colors.
See the ansi-terminal package for more details.
Utilities
You will most likely not need these
runZiftAuto :: (ZiftContext -> Zift ()) -> Settings -> IO () Source #
runZift :: ZiftContext -> Zift a -> IO (ZiftResult a) Source #
ziftRunner :: ZiftContext -> TMVar () -> Zift a -> IO (ZiftResult a) Source #
data LinearState Source #
prettyToken :: ZiftToken -> String Source #
prettyState :: LinearState -> String Source #
processToken :: LinearState -> ZiftToken -> Maybe (LinearState, Buf) Source #
addState :: LinearState -> ZiftToken -> Maybe LinearState Source #
flushState :: LinearState -> (LinearState, Buf) Source #
pruneState :: LinearState -> LinearState Source #
flushStateAll :: LinearState -> Buf Source #