Add more haddock

pull/5/head
Lennart Spitzner 2017-05-16 13:20:28 +02:00
parent c1cbc77e5b
commit 6a4d15e895
3 changed files with 26 additions and 0 deletions

View File

@ -70,6 +70,7 @@ module UI.Butcher.Monadic.Command
, addCmdPartMany , addCmdPartMany
, addCmdPartInp , addCmdPartInp
, addCmdPartManyInp , addCmdPartManyInp
, ManyUpperBound (..)
) )
where where

View File

@ -112,6 +112,7 @@ addCmdHelpStr s = liftF $ CmdParserHelp (PP.text s) ()
-- | Semi-hacky way of accessing the output CommandDesc from inside of a -- | Semi-hacky way of accessing the output CommandDesc from inside of a
-- 'CmdParser'. This is not implemented via knot-tying, i.e. the CommandDesc -- 'CmdParser'. This is not implemented via knot-tying, i.e. the CommandDesc
-- you get is _not_ equivalent to the CommandDesc returned by 'runCmdParser'. -- you get is _not_ equivalent to the CommandDesc returned by 'runCmdParser'.
-- Also see 'runCmdParserWithHelpDesc' which does knot-tying.
-- --
-- For best results, use this "below" -- For best results, use this "below"
-- any 'addCmd' invocations in the current context, e.g. directly before -- any 'addCmd' invocations in the current context, e.g. directly before
@ -119,9 +120,19 @@ addCmdHelpStr s = liftF $ CmdParserHelp (PP.text s) ()
peekCmdDesc :: CmdParser f out (CommandDesc ()) peekCmdDesc :: CmdParser f out (CommandDesc ())
peekCmdDesc = liftF $ CmdParserPeekDesc id peekCmdDesc = liftF $ CmdParserPeekDesc id
-- | Semi-hacky way of accessing the current input that is not yet processed.
-- This must not be used to do any parsing. The purpose of this function is
-- to provide a String to be used for output to the user, as feedback about
-- what command was executed. For example we may think of an interactive
-- program reacting to commandline input such as
-- "run --delay 60 fire-rockets" which shows a 60 second delay on the
-- "fire-rockets" command. The latter string could have been obtained
-- via 'peekInput' after having parsed "run --delay 60" already.
peekInput :: CmdParser f out String peekInput :: CmdParser f out String
peekInput = liftF $ CmdParserPeekInput id peekInput = liftF $ CmdParserPeekInput id
-- | Add part that is expected to occur exactly once in the input. May
-- succeed on empty input (e.g. by having a default).
addCmdPart addCmdPart
:: (Applicative f, Typeable p) :: (Applicative f, Typeable p)
=> PartDesc => PartDesc
@ -137,6 +148,8 @@ addCmdPartA
-> CmdParser f out p -> CmdParser f out p
addCmdPartA p f a = liftF $ CmdParserPart p f a id addCmdPartA p f a = liftF $ CmdParserPart p f a id
-- | Add part that is not required to occur, and can occur as often as
-- indicated by 'ManyUpperBound'. Must not succeed on empty input.
addCmdPartMany addCmdPartMany
:: (Applicative f, Typeable p) :: (Applicative f, Typeable p)
=> ManyUpperBound => ManyUpperBound
@ -154,6 +167,11 @@ addCmdPartManyA
-> CmdParser f out [p] -> CmdParser f out [p]
addCmdPartManyA b p f a = liftF $ CmdParserPartMany b p f a id addCmdPartManyA b p f a = liftF $ CmdParserPartMany b p f a id
-- | Add part that is expected to occur exactly once in the input. May
-- succeed on empty input (e.g. by having a default).
--
-- Only difference to 'addCmdPart' is that it accepts 'Input', i.e. can
-- behave differently for @String@ and @[String]@ input.
addCmdPartInp addCmdPartInp
:: (Applicative f, Typeable p) :: (Applicative f, Typeable p)
=> PartDesc => PartDesc
@ -169,6 +187,11 @@ addCmdPartInpA
-> CmdParser f out p -> CmdParser f out p
addCmdPartInpA p f a = liftF $ CmdParserPartInp p f a id addCmdPartInpA p f a = liftF $ CmdParserPartInp p f a id
-- | Add part that is not required to occur, and can occur as often as
-- indicated by 'ManyUpperBound'. Must not succeed on empty input.
--
-- Only difference to 'addCmdPart' is that it accepts 'Input', i.e. can
-- behave differently for @String@ and @[String]@ input.
addCmdPartManyInp addCmdPartManyInp
:: (Applicative f, Typeable p) :: (Applicative f, Typeable p)
=> ManyUpperBound => ManyUpperBound
@ -1047,6 +1070,7 @@ takeCommandChild key = do
mSet cmd { _cmd_children = children' } mSet cmd { _cmd_children = children' }
return r return r
-- | map over the @out@ type argument
mapOut :: (outa -> outb) -> CmdParser f outa () -> CmdParser f outb () mapOut :: (outa -> outb) -> CmdParser f outa () -> CmdParser f outb ()
mapOut f = hoistFree $ \case mapOut f = hoistFree $ \case
CmdParserHelp doc r -> CmdParserHelp doc r CmdParserHelp doc r -> CmdParserHelp doc r

View File

@ -52,6 +52,7 @@ data ParsingError = ParsingError
} }
deriving (Show, Eq) deriving (Show, Eq)
-- | Specifies whether we accept 0-1 or 0-n for @CmdParserPart@s.
data ManyUpperBound data ManyUpperBound
= ManyUpperBound1 = ManyUpperBound1
| ManyUpperBoundN | ManyUpperBoundN