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

Safe HaskellNone



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 ""
      else "example, version"

  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!"



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:


  example - a simple butcher example program


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


  a very long help document


  --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.