cli-builder

Simple project template from stack https://github.com/uecmma/haskell-library-collections/tree/master/cli-builder

Latest on Hackage:0.1.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed by uecmma

CLI Builder

This packages contains builders to make cli application easily based optparse-applicative.

Getting Started

Here is a simple example:

{-# LANGUAGE RecordWildCards #-}

import System.CLI.Builder

data Options = Options
  { isSampleOption :: Bool
  } deriving (Eq, Show)

optionsParser :: OptionParser Options
optionsParser = Options
  <$> switch (long "sample" <> help "Sample switch")

cliInfo :: CLIInfo
cliInfo = baseCLIInfo "Simple CLI" "Example for simple CLI"

run :: Options -> IO ()
run Options{..} = do
  putStrLn "Sample application"
  putStrLn $ "Is sample: " ++ show isSampleOption

main :: IO ()
main = buildSimpleCLI cliInfo optionsParser run

This action is such as:

$ sampleApp
Sample application
Is sample: False
$ sampleApp --sample
Sample application
Is sample: True
$ sampleApp --help
Simple CLI

Usage: <interactive> [--help]
  Example for simple CLI

Available options:
  --help                   Show this help text
  --sample                 Sample switch

For more examples, see examples.

comments powered byDisqus