butcher-1.1.0.0: Chops a command or program invocation into digestable pieces.

Safe HaskellNone
LanguageHaskell2010

UI.Butcher.Monadic.Pretty

Description

Pretty-print of CommandDescs. To explain what the different functions do, we will use an example CmdParser. The CommandDesc derived from that CmdParser will serve as example input to the functions in this module.

main = mainFromCmdParserWithHelpDesc $ \helpDesc -> do

  addCmdSynopsis "a simple butcher example program"
  addCmdHelpStr "a very long help document"

  addCmd "version" $ do
    porcelain <- addSimpleBoolFlag "" ["porcelain"]
      (flagHelpStr "print nothing but the numeric version")
    addCmdHelpStr "prints the version of this program"
    addCmdImpl $ putStrLn $ if porcelain
      then "0.0.0.999"
      else "example, version 0.0.0.999"

  addCmd "help" $ addCmdImpl $ print $ ppHelpShallow helpDesc

  short <- addSimpleBoolFlag "" ["short"] (flagHelpStr "make the greeting short")
  name <- addStringParam "NAME"
    (paramHelpStr "your name, so you can be greeted properly")

  addCmdImpl $ do
    if short
      then putStrLn $ "hi, " ++ name ++ "!"
      else putStrLn $ "hello, " ++ name ++ ", welcome from butcher!"

Synopsis

Documentation

ppUsage :: CommandDesc a -> Doc Source #

ppUsage exampleDesc yields:

playground [--short] NAME [version | help]

ppUsageAt :: [String] -> CommandDesc a -> Maybe Doc Source #

ppUsageAt [] = ppUsage

fromJust $ ppUsageAt ["version"] exampleDesc yields:

example version [--porcelain]

ppHelpShallow :: CommandDesc a -> Doc Source #

ppHelpShalloe exampleDesc yields:

NAME

  example - a simple butcher example program

USAGE

  example [--short] NAME [version | help]

DESCRIPTION

  a very long help document

ARGUMENTS

  --short             make the greeting short
  NAME                your name, so you can be greeted properly

ppUsageWithHelp :: CommandDesc a -> Doc Source #

ppUsageWithHelp exampleDesc yields:

playground [--short] NAME
           [version | help]: a simple butcher example program

And yes, the line break is not optimal in this instance with default print.

ppPartDescUsage :: PartDesc -> Doc Source #

Internal helper; users probably won't need this.

ppPartDescHeader :: PartDesc -> Doc Source #

Internal helper; users probably won't need this.