structured-cli: Application library for building interactive console CLIs

[ bsd3, console, library, program ] [ Propose Tags ]

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.


[Skip to Readme]
Versions 0.9.0.2, 0.9.0.3, 0.9.1.0, 0.9.2.0, 0.9.3.0, 0.9.3.1, 0.9.4.0, 0.9.4.1, 2.0.0.0, 2.0.0.1, 2.2.0.0, 2.2.1.0, 2.3.0.0, 2.4.0.0, 2.4.0.1
Dependencies base (>=4.7 && <5), data-default, haskeline, mtl, split, structured-cli, transformers [details]
License BSD-3-Clause
Copyright 2017 Erick Gonzalez
Author Erick Gonzalez
Maintainer erick@codemonkeylabs.de
Category Console
Home page https://gitlab.com/codemonkeylabs/structured-cli#readme
Source repo head: git clone https://gitlab.com/codemonkeylabs/structured-cli
Uploaded by erick at Mon Nov 12 22:43:53 UTC 2018
Distributions NixOS:2.4.0.1
Executables some-cli
Downloads 1215 total (182 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-11-12 [all 1 reports]
Hackage Matrix CI

Modules

[Index] [Quick Jump]

Flags

NameDescriptionDefaultType
debug

Enable debug messages

DisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for structured-cli-2.4.0.1

[back to package description]

structured-cli

Haskell library for building structured CLI applications

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.

  • How to use this module:

It is often the case that a simple example is the best user guide, at least for the experienced programmer. The following code illustrates a basic but functioning CLI application:

module Main where

import Control.Monad                 (void)
import Control.Monad.IO.Class        (liftIO)
import Data.Default                  (def)
import System.Console.StructuredCLI

root :: Commands ()
root = do
  world >+ do
    hello
    bye
    command "exit" "return to previous level" exit

world :: Commands ()
world = command "world" "enter into the world" $ return NewLevel

hello :: Commands ()
hello = command "hello" "prints a greeting" $ do
          liftIO . putStrLn $ "Hello world!"
          return NoAction

bye :: Commands ()
bye = command "bye" "say goodbye" $ do
        liftIO . putStrLn $ "Sayonara!"
        return NoAction

main :: IO ()
main = void $ runCLI "Hello CLI" def root

resulting example session:

>>> Hello CLI > ?
- world: enter into the world

>>> Hello CLI > world
>>> Hello CLI world > ?
- exit: return to previous level
- bye: say goodbye
- hello: prints a greeting

>>> Hello CLI world > hello
Hello world!
>>> Hello CLI world > bye
Sayonara!
>>> Hello CLI world > exit
>>> Hello CLI >

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.