structured-cli-0.9.0.3: Application library for building interactive console CLIs

Copyright(c) Erick Gonzalez 2017
LicenseBSD3
Maintainererick@codemonkeylabs.de
Safe HaskellNone
LanguageHaskell2010

System.Console.StructuredCLI

Contents

Description

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.

Synopsis

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 #

Constructors

CommandsT 

Fields

Instances

MonadTrans CommandsT Source # 

Methods

lift :: Monad m => m a -> CommandsT m a #

Monad m => Monad (CommandsT m) Source # 

Methods

(>>=) :: CommandsT m a -> (a -> CommandsT m b) -> CommandsT m b #

(>>) :: CommandsT m a -> CommandsT m b -> CommandsT m b #

return :: a -> CommandsT m a #

fail :: String -> CommandsT m a #

Functor f => Functor (CommandsT f) Source # 

Methods

fmap :: (a -> b) -> CommandsT f a -> CommandsT f b #

(<$) :: a -> CommandsT f b -> CommandsT f a #

Applicative a => Applicative (CommandsT a) Source # 

Methods

pure :: a -> CommandsT a a #

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

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

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

MonadIO m => MonadIO (CommandsT m) Source # 

Methods

liftIO :: IO a -> CommandsT m a #

data Parser m Source #

Instances

MonadIO m => Default (Parser m) Source # 

Methods

def :: Parser m #

data Settings Source #

Constructors

Settings 

Instances

(>+) :: Monad m => CommandsT m () -> CommandsT m () -> CommandsT m () Source #

command :: MonadIO m => String -> Maybe String -> Maybe (Action m) -> CommandsT m () 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 #