butcher-1.3.2.1: 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:

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

ppUsageShortSub :: CommandDesc a -> Doc Source #

ppUsageShortSub exampleDesc yields:

example [--short] NAME <command>

I.e. Subcommands are abbreviated using the command label, instead of being listed.

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

ppUsageAt [] = ppUsage

fromJust $ ppUsageAt ["version"] exampleDesc yields:

example version [--porcelain]

ppHelpShallow :: CommandDesc a -> Doc Source #

ppHelpShallow 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

ppHelpDepthOne :: CommandDesc a -> Doc Source #

ppHelpDepthOne exampleDesc yields:

NAME

  example - a simple butcher example program

USAGE

  example [--short] NAME <command>

DESCRIPTION

  a very long help document

COMMANDS

  version
  help

ARGUMENTS

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

ppUsageWithHelp :: CommandDesc a -> Doc Source #

ppUsageWithHelp exampleDesc yields:

example [--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 -> Maybe Doc Source #

Internal helper; users probably won't need this.

ppPartDescHeader :: PartDesc -> Doc Source #

Internal helper; users probably won't need this.