Copyright | (c) Erick Gonzalez 2017 |
---|---|
License | BSD3 |
Maintainer | erick@codemonkeylabs.de |
Safe Haskell | None |
Language | Haskell2010 |
This module provides the tools to build a complete "structured" CLI application, similar to those found in systems like Cisco IOS or console configuration utilities etc. It aims to be easy for implementors to use.
- type Commands = CommandsT IO
- newtype CommandsT m a = CommandsT {
- runCommandsT :: m (a, [Node m])
- data Parser m
- data ParseResult
- data Settings = Settings {}
- (>+) :: Monad m => CommandsT m () -> CommandsT m () -> CommandsT m ()
- command :: MonadIO m => String -> Maybe String -> Maybe (Action m) -> CommandsT m ()
- exit :: MonadIO m => Maybe String -> CommandsT m ()
- mkParser :: MonadIO m => (Bool -> String -> m ParseResult) -> Parser m
- outputStrLn :: MonadIO m => String -> InputT m ()
- param :: Monad m => String -> Maybe String -> Parser m -> Maybe (Action m) -> CommandsT m ()
- popCommand :: Monad m => CState m ()
- pushCommand :: Monad m => Node m -> String -> CState m ()
- runCLI :: MonadException m => String -> Maybe Settings -> CommandsT m () -> m ()
- top :: MonadIO m => Maybe String -> CommandsT m ()
How to use this module:
The following code illustrates a simple but complete CLI app:
import Control.Monad.IO.Class (liftIO) import System.Console.StructuredCLI root :: Commands () root = do world >+ do hello bye exit $ Just "return to previous level" world :: Commands () world = command "world" (Just "enter into world") Nothing hello :: Commands () hello = command "hello" (Just "prints a greeting") $ Just $ do liftIO . putStrLn $ "Hello world!" return 0 bye :: Commands () bye = command "bye" (Just "say goodbye") $ Just $ do liftIO . putStrLn $ "Sayonara!" return 0 main :: IO () main = runCLI "Hello CLI" Nothing root
resulting example session:
>>>
Hello CLI > ?
- world: enter into world>>>
Hello CLI > world
>>>
Hello CLI world >
bye exit hello>>>
Hello CLI world > hello
Hello world!>>>
Hello CLI world > exit
A good way to get you started is to grab the example code available under example/Main.hs and modify it to suit your needs.
newtype CommandsT m a Source #
CommandsT | |
|
data ParseResult Source #
outputStrLn :: MonadIO m => String -> InputT m () #
Write a string to the user's standard output, followed by a newline.
param :: Monad m => String -> Maybe String -> Parser m -> Maybe (Action m) -> CommandsT m () Source #
popCommand :: Monad m => CState m () Source #
pushCommand :: Monad m => Node m -> String -> CState m () Source #