structured-cli-0.9.4.1: 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.

type Action m = CState m Int Source #

newtype CommandsT m a Source #

Constructors

CommandsT 

Fields

Instances
MonadTrans CommandsT Source # 
Instance details

Defined in System.Console.StructuredCLI

Methods

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

Monad m => Monad (CommandsT m) Source # 
Instance details

Defined in System.Console.StructuredCLI

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 # 
Instance details

Defined in System.Console.StructuredCLI

Methods

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

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

Applicative a => Applicative (CommandsT a) Source # 
Instance details

Defined in System.Console.StructuredCLI

Methods

pure :: a0 -> CommandsT a a0 #

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

liftA2 :: (a0 -> b -> c) -> CommandsT a a0 -> CommandsT a b -> CommandsT a c #

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

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

MonadIO m => MonadIO (CommandsT m) Source # 
Instance details

Defined in System.Console.StructuredCLI

Methods

liftIO :: IO a -> CommandsT m a #

data Parser m Source #

Instances
MonadIO m => Default (Parser m) Source # 
Instance details

Defined in System.Console.StructuredCLI

Methods

def :: Parser m #

data Settings Source #

Constructors

Settings 
Instances
Default Settings Source # 
Instance details

Defined in System.Console.StructuredCLI

Methods

def :: Settings #

data State m Source #

Constructors

State 

Fields

(>+) :: Monad m => CommandsT m () -> CommandsT 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 #