Safe Haskell | None |
---|---|
Language | Haskell2010 |
Stackage.CLI
Description
Functions for creating and calling Stackage plugins.
- runStackagePlugin :: Text -> [String] -> IO ()
- data Plugins
- findPlugins :: Text -> IO Plugins
- callPlugin :: (MonadIO m, MonadThrow m) => Plugins -> Text -> [String] -> m ()
- data PluginException
- commandsFromPlugins :: Plugins -> EitherT Text (Writer (Mod CommandFields Text)) ()
- simpleOptions :: String -> String -> String -> Parser a -> EitherT b (Writer (Mod CommandFields b)) () -> IO (a, b)
- addCommand :: String -> String -> (a -> b) -> Parser a -> EitherT b (Writer (Mod CommandFields b)) ()
- simpleVersion :: Version -> Q Exp
- listPlugins :: Plugins -> [Plugin]
- lookupPlugin :: Plugins -> Text -> Maybe Plugin
- data Plugin
- pluginPrefix :: Plugin -> Text
- pluginName :: Plugin -> Text
- pluginSummary :: Plugin -> Text
- pluginProc :: Plugin -> [String] -> CreateProcess
Discovering and calling plugins
runStackagePlugin :: Text -> [String] -> IO () Source
Runs a stackage plugin. Handy for dynamic one-off runs,
but if you'll be running multiple plugins, it is recommended
that you use findPlugins "stackage"
so that the plugin search
is performed only once.
Represents the plugins available to a given program.
See: findPlugins
.
findPlugins :: Text -> IO Plugins Source
Find the plugins for a given program by inspecting everything on the PATH. Any program that is prefixed with the given name and responds to the `--summary` flag by writing one line to stdout is considered a plugin.
callPlugin :: (MonadIO m, MonadThrow m) => Plugins -> Text -> [String] -> m () Source
A convenience wrapper around lookupPlugin and pluginProc. Handles stdin, stdout, and stderr are all inherited by the plugin. Throws PluginException.
data PluginException Source
Things that can go wrong when using callPlugin
.
Constructors
PluginNotFound !Plugins !Text | |
PluginExitFailure !Plugin !Int |
Creating your own plugin
commandsFromPlugins :: Plugins -> EitherT Text (Writer (Mod CommandFields Text)) () Source
Generate the "commands" argument to simpleOptions based on available plugins.
Arguments
:: String | version string |
-> String | header |
-> String | program description |
-> Parser a | global settings |
-> EitherT b (Writer (Mod CommandFields b)) () | commands (use |
-> IO (a, b) |
This is a drop-in replacement for simpleOptions from Options.Applicative.Simple, with the added feature of a `--summary` flag that prints out the header. (Should be one line)
Arguments
:: String | command string |
-> String | title of command |
-> (a -> b) | constructor to wrap up command in common data type |
-> Parser a | command parser |
-> EitherT b (Writer (Mod CommandFields b)) () |
Add a command to the options dispatcher.
simpleVersion :: Version -> Q Exp
Generate a string like Version 1.2, Git revision 1234
.
$(simpleVersion …)
::
String
Finer-grained inspection of plugins
listPlugins :: Plugins -> [Plugin] Source
List the available plugins.
Represents a runnable plugin.
Plugins must be discovered via findPlugins
.
pluginPrefix :: Plugin -> Text Source
The program being plugged into.
pluginName :: Plugin -> Text Source
The name of this plugin (without the prefix).
pluginSummary :: Plugin -> Text Source
A summary of what this plugin does
pluginProc :: Plugin -> [String] -> CreateProcess Source
Describes how to create a process out of a plugin and arguments. You may use Data.Process and Data.Conduit.Process to manage the process's stdin, stdout, and stderr in various ways.