Safe Haskell | None |
---|---|
Language | Haskell2010 |
System.Console.Docopt.NoTH
Contents
Synopsis
- parseUsage :: String -> Either ParseError Docopt
- parseUsageOrExit :: String -> IO Docopt
- argument :: String -> Option
- command :: String -> Option
- exitWithUsage :: Docopt -> IO a
- exitWithUsageMessage :: Docopt -> String -> IO a
- getAllArgs :: Arguments -> Option -> [String]
- getAllArgsM :: Monad m => Arguments -> Option -> m [String]
- getArg :: Arguments -> Option -> Maybe String
- getArgCount :: Arguments -> Option -> Int
- getArgOrExitWith :: Docopt -> Arguments -> Option -> IO String
- getArgWithDefault :: Arguments -> String -> Option -> String
- getFirstArg :: MonadFail m => Arguments -> Option -> m String
- isPresent :: Arguments -> Option -> Bool
- isPresentM :: Monad m => Arguments -> Option -> m Bool
- longOption :: String -> Option
- notPresent :: Arguments -> Option -> Bool
- notPresentM :: Monad m => Arguments -> Option -> m Bool
- parseArgs :: Docopt -> [String] -> Either ParseError Arguments
- parseArgsOrExit :: Docopt -> [String] -> IO Arguments
- shortOption :: Char -> Option
- type Arguments = Map Option ArgValue
- data Docopt
- data Option
- data ParseError
Usage parsers
parseUsage :: String -> Either ParseError Docopt Source #
Parse docopt-formatted usage patterns.
For help with the docopt usage format, see the readme on github.
parseUsageOrExit :: String -> IO Docopt Source #
Same as parseUsage
, but exitWithUsage
on parse failure. E.g.
let usageStr = "Usage:\n prog [--option]\n" patterns <- parseUsageOrExit usageStr
argument :: String -> Option Source #
For Usage: prog <file>
, ask for argument "file"
.
Note: A Usage: prog --output=<file>
is not matched by argument "file"
. See longOption
.
command :: String -> Option Source #
For Usage: prog cmd
, ask for command "cmd"
.
For Usage: prog -
or Usage: prog [-]
, ask for command "-"
. Same for --
.
exitWithUsage :: Docopt -> IO a Source #
Exit after printing usage text.
exitWithUsageMessage :: Docopt -> String -> IO a Source #
Exit after printing a custom message followed by usage text. Intended for convenience when more context can be given about what went wrong.
getAllArgs :: Arguments -> Option -> [String] Source #
Returns all occurrences of a repeatable option, e.g. <file>...
.
getAllArgsM :: Monad m => Arguments -> Option -> m [String] Source #
Deprecated: Monadic query functions will soon be removed
getArgCount :: Arguments -> Option -> Int Source #
Return the number of occurrences of an option in an invocation.
Useful with repeatable flags, e.g. [ -v | -vv | -vvv]
.
getArgOrExitWith :: Docopt -> Arguments -> Option -> IO String Source #
Same as getArg
, but exitWithUsage
if Nothing
.
As in getArg
, if your usage pattern required the option, getArgOrExitWith
will not exit.
getFirstArg :: MonadFail m => Arguments -> Option -> m String Source #
Deprecated: Use getAllArgs
instead
isPresent :: Arguments -> Option -> Bool Source #
True
if an option was present at all in an invocation.
Useful with longOption
s and shortOption
s, and in conjunction with when
.
isPresentM :: Monad m => Arguments -> Option -> m Bool Source #
Deprecated: Monadic query functions will soon be removed
longOption :: String -> Option Source #
For Usage: prog --version
, ask for longOption "version"
.
For Usage: prog --output=<file>
, ask for longOption "output"
.
notPresentM :: Monad m => Arguments -> Option -> m Bool Source #
Deprecated: Monadic query functions will soon be removed
parseArgs :: Docopt -> [String] -> Either ParseError Arguments Source #
Parse command line arguments.
parseArgsOrExit :: Docopt -> [String] -> IO Arguments Source #
Same as parseArgs
, but exitWithUsage
on parse failure. E.g.
args <- parseArgsOrExit patterns =<< getArgs
shortOption :: Char -> Option Source #
For Usage: prog -h
, ask for shortOption 'h'
.
For Usage: prog -o=<file>
, ask for shortOption 'o'
.
type Arguments = Map Option ArgValue Source #
Maps each Option to all of the valued parsed from the command line (in order of last to first, if multiple values encountered)
An abstract data type which represents Docopt usage patterns.
A named leaf node of the usage pattern tree
data ParseError #
The abstract data type ParseError
represents parse errors. It
provides the source position (SourcePos
) of the error
and a list of error messages (Message
). A ParseError
can be returned by the function parse
. ParseError
is an
instance of the Show
and Eq
classes.
Instances
Exception ParseError # | Since: parsec-3.1.17.0 |
Defined in Text.Parsec.Error Methods toException :: ParseError -> SomeException # fromException :: SomeException -> Maybe ParseError # displayException :: ParseError -> String # backtraceDesired :: ParseError -> Bool # | |
Show ParseError # | |
Defined in Text.Parsec.Error Methods showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS # | |
Eq ParseError # | |
Defined in Text.Parsec.Error |