-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Utilities and combinators for parsing command line options -- -- Here is a simple example of an applicative option parser: -- --
-- data Sample = Sample
-- { hello :: String
-- , quiet :: Bool }
--
-- sample :: Parser Sample
-- sample = Sample
-- <$> strOption
-- ( long "hello"
-- <> metavar "TARGET"
-- <> help "Target for the greeting" )
-- <*> switch
-- ( long "quiet"
-- <> help "Whether to be quiet" )
--
--
-- The parser is built using applicative style starting from a set of
-- basic combinators. In this example, hello is defined as an
-- option with a String argument, while quiet is
-- a boolean flag (called switch).
--
-- A parser can be used like this:
--
-- -- greet :: Sample -> IO () -- greet (Sample h False) = putStrLn $ "Hello, " ++ h -- greet _ = return () -- -- main :: IO () -- main = execParser opts >>= greet -- where -- opts = info (helper <*> sample) -- ( fullDesc -- <> progDesc "Print a greeting for TARGET" -- <> header "hello - a test for optparse-applicative" ) ---- -- The greet function is the entry point of the program, while -- opts is a complete description of the program, used when -- generating a help text. The helper combinator takes any parser, -- and adds a help option to it (which always fails). -- -- The hello option in this example is mandatory (since it -- doesn't have a default value), so running the program without any -- argument will display a help text: -- --
-- hello - a test for optparse-applicative -- -- Usage: hello --hello TARGET [--quiet] -- Print a greeting for TARGET -- -- Available options: -- -h,--help Show this help text -- --hello TARGET Target for the greeting -- --quiet Whether to be quiet ---- -- containing a short usage summary, and a detailed list of options with -- descriptions. @package optparse-applicative @version 0.8.1 module Options.Applicative.Help.Pretty (.$.) :: Doc -> Doc -> Doc module Options.Applicative.Help.Chunk mappendWith :: Monoid a => a -> a -> a -> a -- | The free monoid on a semigroup a. newtype Chunk a Chunk :: Maybe a -> Chunk a unChunk :: Chunk a -> Maybe a -- | Given a semigroup structure on a, return a monoid structure -- on 'Chunk a'. -- -- Note that this is not the same as liftA2. chunked :: (a -> a -> a) -> Chunk a -> Chunk a -> Chunk a -- | Concatenate a list into a Chunk. listToChunk satisfies: -- --
-- isEmpty . listToChunk = null -- listToChunk = mconcat . fmap pure --listToChunk :: Monoid a => [a] -> Chunk a -- | Concatenate two Chunks with a space in between. If one is -- empty, this just returns the other one. -- -- Unlike <+> for Doc, this operation has a unit -- element, namely the empty Chunk. (<<+>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc -- | Concatenate two Chunks with a softline in between. This is -- exactly like <<+>>, but uses a softline instead of -- a space. (<>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc -- | Concatenate Chunks vertically. vcatChunks :: [Chunk Doc] -> Chunk Doc -- | Concatenate Chunks vertically separated by empty lines. vsepChunks :: [Chunk Doc] -> Chunk Doc -- | Whether a Chunk is empty. Note that something like 'pure -- mempty' is not considered an empty chunk, even though the underlying -- Doc is empty. isEmpty :: Chunk a -> Bool -- | Convert a String into a Chunk. This satisfies: -- --
-- isEmpty . stringChunk = null -- extractChunk . stringChunk = string --stringChunk :: String -> Chunk Doc -- | Convert a paragraph into a Chunk. The resulting chunk is -- composed by the words of the original paragraph separated by -- softlines, so it will be automatically word-wrapped when rendering the -- underlying document. -- -- This satisfies: -- --
-- isEmpty . paragraph = null . words --paragraph :: String -> Chunk Doc -- | Part of a constrained comonad instance. -- -- This is the counit of the adjunction between Chunk and the -- forgetful functor from monoids to semigroups. It satisfies: -- --
-- extractChunk . pure = id -- extractChunk . fmap pure = id --extractChunk :: Monoid a => Chunk a -> a -- | Display pairs of strings in a table. tabulate :: [(Doc, Doc)] -> Chunk Doc instance Eq a => Eq (Chunk a) instance Show a => Show (Chunk a) instance Monoid a => Monoid (Chunk a) instance MonadPlus Chunk instance Monad Chunk instance Applicative Chunk instance Functor Chunk module Options.Applicative.Types data ParseError ErrorMsg :: String -> ParseError InfoMsg :: String -> ParseError ShowHelpText :: ParseError -- | A full description for a runnable Parser for a program. data ParserInfo a ParserInfo :: Parser a -> Bool -> Chunk Doc -> Chunk Doc -> Chunk Doc -> Int -> Bool -> ParserInfo a -- | the option parser for the program infoParser :: ParserInfo a -> Parser a -- | whether the help text should contain full documentation infoFullDesc :: ParserInfo a -> Bool -- | brief parser description infoProgDesc :: ParserInfo a -> Chunk Doc -- | header of the full parser description infoHeader :: ParserInfo a -> Chunk Doc -- | footer of the full parser description infoFooter :: ParserInfo a -> Chunk Doc -- | exit code for a parser failure infoFailureCode :: ParserInfo a -> Int -- | allow regular options and flags to occur after arguments (default: -- True) infoIntersperse :: ParserInfo a -> Bool -- | Global preferences for a top-level Parser. data ParserPrefs ParserPrefs :: String -> Bool -> Bool -> Bool -> Int -> ParserPrefs -- | metavar suffix for multiple options prefMultiSuffix :: ParserPrefs -> String -- | automatically disambiguate abbreviations (default: False) prefDisambiguate :: ParserPrefs -> Bool -- | always show help text on parse errors (default: False) prefShowHelpOnError :: ParserPrefs -> Bool -- | backtrack to parent parser when a subcommand fails (default: True) prefBacktrack :: ParserPrefs -> Bool -- | number of columns in the terminal, used to format the help page -- (default: 80) prefColumns :: ParserPrefs -> Int -- | A single option of a parser. data Option a Option :: OptReader a -> OptProperties -> Option a -- | reader for this option optMain :: Option a -> OptReader a -- | properties of this option optProps :: Option a -> OptProperties data OptName OptShort :: !Char -> OptName OptLong :: !String -> OptName -- | An OptReader defines whether an option matches an command line -- argument. data OptReader a -- | option reader OptReader :: [OptName] -> (OptCReader a) -> ParseError -> OptReader a -- | flag reader FlagReader :: [OptName] -> !a -> OptReader a -- | argument reader ArgReader :: (ArgCReader a) -> OptReader a -- | command reader CmdReader :: [String] -> (String -> Maybe (ParserInfo a)) -> OptReader a -- | Specification for an individual parser option. data OptProperties OptProperties :: OptVisibility -> Chunk Doc -> String -> Maybe String -> OptProperties -- | whether this flag is shown is the brief description propVisibility :: OptProperties -> OptVisibility -- | help text for this option propHelp :: OptProperties -> Chunk Doc -- | metavariable for this option propMetaVar :: OptProperties -> String -- | what to show in the help text as the default propShowDefault :: OptProperties -> Maybe String -- | Visibility of an option in the help text. data OptVisibility -- | does not appear in the help text at all Internal :: OptVisibility -- | only visible in the full description Hidden :: OptVisibility -- | visible both in the full and brief descriptions Visible :: OptVisibility -- | A newtype over the Either monad used by option readers. newtype ReadM a ReadM :: Either ParseError a -> ReadM a runReadM :: ReadM a -> Either ParseError a -- | Abort option reader by exiting with a ParseError. readerAbort :: ParseError -> ReadM a -- | Abort option reader by exiting with an error message. readerError :: String -> ReadM a data CReader m a CReader :: Completer -> (String -> m a) -> CReader m a crCompleter :: CReader m a -> Completer crReader :: CReader m a -> String -> m a -- | A Parser a is an option parser returning a value of type -- a. data Parser a NilP :: Maybe a -> Parser a OptP :: Option a -> Parser a MultP :: Parser (a -> b) -> Parser a -> Parser b AltP :: Parser a -> Parser a -> Parser a BindP :: Parser a -> (a -> Parser b) -> Parser b newtype ParserM r ParserM :: (forall x. (r -> Parser x) -> Parser x) -> ParserM r runParserM :: ParserM r -> forall x. (r -> Parser x) -> Parser x newtype Completer Completer :: (String -> IO [String]) -> Completer runCompleter :: Completer -> String -> IO [String] mkCompleter :: (String -> IO [String]) -> Completer newtype CompletionResult CompletionResult :: (String -> IO String) -> CompletionResult execCompletion :: CompletionResult -> String -> IO String newtype ParserFailure ParserFailure :: (String -> (String, ExitCode)) -> ParserFailure execFailure :: ParserFailure -> String -> (String, ExitCode) -- | Result of execParserPure. data ParserResult a Success :: a -> ParserResult a Failure :: ParserFailure -> ParserResult a CompletionInvoked :: CompletionResult -> ParserResult a type Args = [String] data ArgPolicy SkipOpts :: ArgPolicy AllowOpts :: ArgPolicy data OptHelpInfo OptHelpInfo :: Bool -> Bool -> OptHelpInfo hinfoMulti :: OptHelpInfo -> Bool hinfoDefault :: OptHelpInfo -> Bool data OptTree a Leaf :: a -> OptTree a MultNode :: [OptTree a] -> OptTree a AltNode :: [OptTree a] -> OptTree a fromM :: ParserM a -> Parser a oneM :: Parser a -> ParserM a manyM :: Parser a -> ParserM [a] someM :: Parser a -> ParserM [a] optVisibility :: Option a -> OptVisibility optMetaVar :: Option a -> String optHelp :: Option a -> Chunk Doc optShowDefault :: Option a -> Maybe String instance Show ParseError instance Eq OptName instance Ord OptName instance Eq OptVisibility instance Ord OptVisibility instance Eq ArgPolicy instance Show a => Show (OptTree a) instance Monoid Completer instance Alternative Parser instance Applicative ParserM instance Functor ParserM instance Monad ParserM instance Applicative Parser instance Functor Parser instance Functor OptReader instance MonadPlus ReadM instance Monad ReadM instance Applicative ReadM instance Functor ReadM instance Functor m => Functor (CReader m) instance Functor Option instance Functor ParserInfo instance Error ParseError module Options.Applicative.Internal data P a data Context Context :: [String] -> ParserInfo a -> Context NullContext :: Context class (Alternative m, MonadPlus m) => MonadP m setContext :: MonadP m => Maybe String -> ParserInfo a -> m () setParser :: MonadP m => Maybe String -> Parser a -> m () getPrefs :: MonadP m => m ParserPrefs missingArgP :: MonadP m => ParseError -> Completer -> m a tryP :: MonadP m => m a -> m (Either ParseError a) errorP :: MonadP m => ParseError -> m a exitP :: MonadP m => Parser b -> Maybe a -> m a data ParseError ErrorMsg :: String -> ParseError InfoMsg :: String -> ParseError ShowHelpText :: ParseError uncons :: [a] -> Maybe (a, [a]) hoistMaybe :: MonadPlus m => Maybe a -> m a hoistEither :: MonadP m => Either ParseError a -> m a runP :: P a -> ParserPrefs -> (Either ParseError a, Context) data Completion a runCompletion :: Completion r -> ParserPrefs -> Maybe (Either SomeParser Completer) data SomeParser SomeParser :: Parser a -> SomeParser data ComplError ComplParseError :: String -> ComplError ComplExit :: ComplError data ListT m a takeListT :: Monad m => Int -> ListT m a -> ListT m a runListT :: Monad m => ListT m a -> m [a] data NondetT m a cut :: Monad m => NondetT m () () :: Monad m => NondetT m a -> NondetT m a -> NondetT m a disamb :: Monad m => Bool -> NondetT m a -> m (Maybe a) instance MonadTrans NondetT instance Monad m => Alternative (NondetT m) instance Monad m => MonadPlus (NondetT m) instance Monad m => Monad (NondetT m) instance Monad m => Applicative (NondetT m) instance Monad m => Functor (NondetT m) instance Monad m => MonadPlus (ListT m) instance MonadTrans ListT instance Monad m => Alternative (ListT m) instance Monad m => Monad (ListT m) instance Monad m => Applicative (ListT m) instance Monad m => Functor (ListT m) instance MonadP Completion instance MonadPlus Completion instance Monad Completion instance Alternative Completion instance Applicative Completion instance Functor Completion instance Monad ComplResult instance Applicative ComplResult instance Functor ComplResult instance Error ComplError instance MonadP P instance Monoid Context instance MonadPlus P instance Monad P instance Alternative P instance Applicative P instance Functor P module Options.Applicative.Builder.Completer data Completer mkCompleter :: (String -> IO [String]) -> Completer listIOCompleter :: IO [String] -> Completer listCompleter :: [String] -> Completer bashCompleter :: String -> Completer module Options.Applicative.Common -- | A Parser a is an option parser returning a value of type -- a. data Parser a -- | Create a parser composed of a single option. liftOpt :: Option a -> Parser a showOption :: OptName -> String -- | A full description for a runnable Parser for a program. data ParserInfo a ParserInfo :: Parser a -> Bool -> Chunk Doc -> Chunk Doc -> Chunk Doc -> Int -> Bool -> ParserInfo a -- | the option parser for the program infoParser :: ParserInfo a -> Parser a -- | whether the help text should contain full documentation infoFullDesc :: ParserInfo a -> Bool -- | brief parser description infoProgDesc :: ParserInfo a -> Chunk Doc -- | header of the full parser description infoHeader :: ParserInfo a -> Chunk Doc -- | footer of the full parser description infoFooter :: ParserInfo a -> Chunk Doc -- | exit code for a parser failure infoFailureCode :: ParserInfo a -> Int -- | allow regular options and flags to occur after arguments (default: -- True) infoIntersperse :: ParserInfo a -> Bool -- | Global preferences for a top-level Parser. data ParserPrefs ParserPrefs :: String -> Bool -> Bool -> Bool -> Int -> ParserPrefs -- | metavar suffix for multiple options prefMultiSuffix :: ParserPrefs -> String -- | automatically disambiguate abbreviations (default: False) prefDisambiguate :: ParserPrefs -> Bool -- | always show help text on parse errors (default: False) prefShowHelpOnError :: ParserPrefs -> Bool -- | backtrack to parent parser when a subcommand fails (default: True) prefBacktrack :: ParserPrefs -> Bool -- | number of columns in the terminal, used to format the help page -- (default: 80) prefColumns :: ParserPrefs -> Int runParserInfo :: MonadP m => ParserInfo a -> Args -> m a runParserFully :: MonadP m => ArgPolicy -> Parser a -> Args -> m a -- | Apply a Parser to a command line, and return a result and -- leftover arguments. This function returns an error if any parsing -- error occurs, or if any options are missing and don't have a default -- value. runParser :: MonadP m => ArgPolicy -> Parser a -> Args -> m (a, Args) -- | The default value of a Parser. This function returns an error -- if any of the options don't have a default value. evalParser :: Parser a -> Maybe a -- | Map a polymorphic function over all the options of a parser, and -- collect the results in a list. mapParser :: (forall x. OptHelpInfo -> Option x -> b) -> Parser a -> [b] -- | Like mapParser, but collect the results in a tree structure. treeMapParser :: (forall x. OptHelpInfo -> Option x -> b) -> Parser a -> OptTree b optionNames :: OptReader a -> [OptName] instance Monoid MatchResult module Options.Applicative.Builder.Internal -- | An option modifier. -- -- Option modifiers are values that represent a modification of the -- properties of an option. -- -- The type parameter a is the return type of the option, while -- f is a record containing its properties (e.g. -- OptionFields for regular options, FlagFields for flags, -- etc...). -- -- An option modifier consists of 3 elements: -- --
-- length <$> many (flag' () (short 't')) ---- -- is a parser that counts the number of -t arguments on the -- command line. flag' :: a -> Mod FlagFields a -> Parser a -- | Builder for a boolean flag. -- --
-- switch = flag False True --switch :: Mod FlagFields Bool -> Parser Bool -- | Builder for an option with a null reader. A non-trivial reader can be -- added using the reader modifier. nullOption :: Mod OptionFields a -> Parser a -- | An option that always fails. -- -- When this option is encountered, the option parser immediately aborts -- with the given parse error. If you simply want to output a message, -- use infoOption instead. abortOption :: ParseError -> Mod OptionFields (a -> a) -> Parser (a -> a) -- | An option that always fails and displays a message. infoOption :: String -> Mod OptionFields (a -> a) -> Parser (a -> a) -- | Builder for an option taking a String argument. strOption :: Mod OptionFields String -> Parser String -- | Builder for an option using the auto reader. option :: Read a => Mod OptionFields a -> Parser a -- | Specify a short name for an option. short :: HasName f => Char -> Mod f a -- | Specify a long name for an option. long :: HasName f => String -> Mod f a -- | Specify the help text for an option. help :: String -> Mod f a -- | Specify the help text for an option as a Doc value. helpDoc :: Maybe Doc -> Mod f a -- | Specify a default value for an option. value :: HasValue f => a -> Mod f a -- | Specify a function to show the default value for an option. showDefaultWith :: (a -> String) -> Mod f a -- | Show the default value for this option using its Show instance. showDefault :: Show a => Mod f a -- | Specify the metavariable. metavar :: HasMetavar f => String -> Mod f a -- | Specify the Option reader. reader :: (String -> ReadM a) -> Mod OptionFields a -- | Specify the Option reader as a function in the Either -- monad. eitherReader :: (String -> Either String a) -> Mod OptionFields a -- | Specify the error to display when no argument is provided to this -- option. noArgError :: ParseError -> Mod OptionFields a data ParseError ErrorMsg :: String -> ParseError InfoMsg :: String -> ParseError ShowHelpText :: ParseError -- | Hide this option from the brief description. hidden :: Mod f a -- | Hide this option from the help text internal :: Mod f a -- | Add a command to a subparser option. command :: String -> ParserInfo a -> Mod CommandFields a -- | Add a list of possible completion values. completeWith :: HasCompleter f => [String] -> Mod f a -- | Add a bash completion action. Common actions include file and -- directory. See -- http:www.gnu.orgsoftwarebashmanualhtml_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins -- for a complete list. action :: HasCompleter f => String -> Mod f a -- | Add a completer to an argument. -- -- A completer is a function String -> IO String which, given a -- partial argument, returns all possible completions for that argument. completer :: HasCompleter f => Completer -> Mod f a -- | Trivial option modifier. idm :: Monoid m => m -- | Compose modifiers. -- | Deprecated: Use () instead (&) :: Monoid m => m -> m -> m -- | An infix synonym for mappend. (<>) :: Monoid m => m -> m -> m -- | An associative operation mappend :: Monoid a => a -> a -> a -- | Option reader based on the Read type class. auto :: Monad m => Read a => String -> m a -- | String Option reader. str :: Monad m => String -> m String -- | Null Option reader. All arguments will fail validation. disabled :: Monad m => String -> m a -- | Abort option reader by exiting with a ParseError. readerAbort :: ParseError -> ReadM a -- | Abort option reader by exiting with an error message. readerError :: String -> ReadM a -- | Modifier for ParserInfo. data InfoMod a -- | Show a full description in the help text of this parser. fullDesc :: InfoMod a -- | Only show a brief description in the help text of this parser. briefDesc :: InfoMod a -- | Specify a header for this parser. header :: String -> InfoMod a -- | Specify a header for this parser as a Doc value. headerDoc :: Maybe Doc -> InfoMod a -- | Specify a footer for this parser. footer :: String -> InfoMod a -- | Specify a footer for this parser as a Doc value. footerDoc :: Maybe Doc -> InfoMod a -- | Specify a short program description. progDesc :: String -> InfoMod a -- | Specify a short program description as a Doc value. progDescDoc :: Maybe Doc -> InfoMod a -- | Specify an exit code if a parse error occurs. failureCode :: Int -> InfoMod a -- | Disable parsing of regular options after arguments noIntersperse :: InfoMod a -- | Create a ParserInfo given a Parser and a modifier. info :: Parser a -> InfoMod a -> ParserInfo a data PrefsMod multiSuffix :: String -> PrefsMod disambiguate :: PrefsMod showHelpOnError :: PrefsMod noBacktrack :: PrefsMod columns :: Int -> PrefsMod prefs :: PrefsMod -> ParserPrefs -- | An option modifier. -- -- Option modifiers are values that represent a modification of the -- properties of an option. -- -- The type parameter a is the return type of the option, while -- f is a record containing its properties (e.g. -- OptionFields for regular options, FlagFields for flags, -- etc...). -- -- An option modifier consists of 3 elements: -- --
-- data Options = Options
-- { optArgs :: [String]
-- , optVerbose :: Bool }
--
-- opts :: Parser Options
-- opts = runA $ proc () -> do
-- verbose <- asA (switch (short 'v')) -< ()
-- args <- asA (arguments str idm) -< ()
-- returnA -< Options args verbose
--
--
-- Parser arrows, created out of regular Parser values using the
-- asA function, are arrows taking () as argument and
-- returning the parsed value.
module Options.Applicative.Arrows
-- | For any Applicative functor f, A f is the
-- Arrow instance associated to f.
--
-- The A constructor can be used to convert a value of type f
-- (a -> b) into an arrow.
newtype A f a b
A :: f (a -> b) -> A f a b
unA :: A f a b -> f (a -> b)
-- | Convert a value of type f a into an arrow taking ()
-- as argument.
--
-- Applied to a value of type Parser, it turns it into an arrow
-- that can be used inside an arrow command, or passed to arrow
-- combinators.
asA :: Applicative f => f a -> A f () a
-- | Convert an arrow back to an applicative value.
--
-- This function can be used to return a result of type Parser
-- from an arrow command.
runA :: Applicative f => A f () a -> f a
-- | The type of arrows associated to the applicative Parser
-- functor.
type ParserA = A Parser
instance Applicative f => Arrow (A f)
instance Applicative f => Category (A f)