Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Multiarg.Mode.Internal
Description
Internal functions used by Multiarg.Mode. You don't have to worry about "breaking" anything by using this module; it is separate from Multiarg.Mode primarily to tidy up the documentation in that module. The functions in Multiarg.Mode should satisfy most use cases. However, if you want more control over error handling, you can use this module.
- newtype ModeName = ModeName String
- data ParsedMode a
- = ModeGood a
- | ModeError [OptionError] (Either OptionError OptName)
- data Mode r = Mode ModeName ([Word] -> ParsedMode r)
- parsedCommandLineToParsedMode :: ([a] -> r) -> ParsedCommandLine a -> ParsedMode r
- mode :: String -> [OptSpec a] -> (String -> a) -> ([a] -> r) -> Mode r
- data GlobalLocalEnd a
- data GlobalLocal g r = GlobalLocal [Either OptionError g] (GlobalLocalEnd r)
- data ModeResult g r = ModeResult [g] (Either [String] r)
- getModeResult :: GlobalLocal g r -> Either (String, [String]) (ModeResult g r)
- combine :: Either (OptionError, [OptionError]) [g] -> Either (String, [String]) (Either [String] r) -> Either (String, [String]) (ModeResult g r)
- endToModeResult :: GlobalLocalEnd a -> Either (String, [String]) (Either [String] a)
- extractParsedMode :: ParsedMode a -> Either (String, [String]) (Either b a)
- globalOptErrorToString :: OptionError -> String
- modeOptErrorToString :: OptionError -> String
- optErrorToString :: String -> OptionError -> String
- eiToError :: Either OptionError OptName -> String
- labeledInsufficientOptArgs :: String -> OptName -> String
- parseModeLine :: [OptSpec g] -> [Mode r] -> [String] -> Either (String, [String]) (ModeResult g r)
- parseModeLineWithErrors :: [OptSpec g] -> [Mode r] -> [String] -> GlobalLocal g r
- findExactMode :: Word -> [Mode a] -> Maybe (Mode a)
Documentation
data ParsedMode a Source
Constructors
ModeGood a | |
ModeError [OptionError] (Either OptionError OptName) | There was an error. There may be zero or more initial OptionError. There must be at least one error, which is either an OptionError or the name of an option, if the error is that there were not enough words following the option to provide it with its necessary arguments. |
Instances
Functor ParsedMode | |
Eq a => Eq (ParsedMode a) | |
Ord a => Ord (ParsedMode a) | |
Show a => Show (ParsedMode a) |
A Mode
represents a single command line mode, such as check
for ghc-pkg check
. It contains the name of the mode, as well as
a parser that handles all options and positional arguments for
the mode. Ordinarily you will create a Mode
using the mode
function rather than by using the constructor directly.
Constructors
Mode ModeName ([Word] -> ParsedMode r) |
parsedCommandLineToParsedMode :: ([a] -> r) -> ParsedCommandLine a -> ParsedMode r Source
Arguments
:: String | Mode name. For instance, for the |
-> [OptSpec a] | Mode options |
-> (String -> a) | Parses positional arguments |
-> ([a] -> r) | Processes the result of all mode options |
-> Mode r |
Creates a new Mode
.
data GlobalLocalEnd a Source
Constructors
GlobalInsufficientOptArgs OptName | |
ModeNotFound String [String] | |
NoMode | |
ModeFound (ParsedMode a) |
Instances
Eq a => Eq (GlobalLocalEnd a) | |
Ord a => Ord (GlobalLocalEnd a) | |
Show a => Show (GlobalLocalEnd a) |
data GlobalLocal g r Source
Constructors
GlobalLocal [Either OptionError g] (GlobalLocalEnd r) |
Instances
(Eq g, Eq r) => Eq (GlobalLocal g r) | |
(Ord g, Ord r) => Ord (GlobalLocal g r) | |
(Show g, Show r) => Show (GlobalLocal g r) |
data ModeResult g r Source
The result of parsing a mode command line.
Constructors
ModeResult [g] (Either [String] r) |
If |
Instances
(Eq g, Eq r) => Eq (ModeResult g r) | |
(Ord g, Ord r) => Ord (ModeResult g r) | |
(Show g, Show r) => Show (ModeResult g r) |
getModeResult :: GlobalLocal g r -> Either (String, [String]) (ModeResult g r) Source
Arguments
:: Either (OptionError, [OptionError]) [g] | Global result. Contains either one or more errors, or global option results. |
-> Either (String, [String]) (Either [String] r) | Result of parsing mode word, and the mode options and
positional arguments. May be |
-> Either (String, [String]) (ModeResult g r) |
endToModeResult :: GlobalLocalEnd a -> Either (String, [String]) (Either [String] a) Source
extractParsedMode :: ParsedMode a -> Either (String, [String]) (Either b a) Source
optErrorToString :: String -> OptionError -> String Source
labeledInsufficientOptArgs :: String -> OptName -> String Source
Arguments
:: [OptSpec g] | Global options. This might, for example, include a |
-> [Mode r] | All modes |
-> [String] | All command line words |
-> Either (String, [String]) (ModeResult g r) | Returns
|
Parses a command line that may contain modes.
parseModeLineWithErrors Source
Arguments
:: [OptSpec g] | Global options |
-> [Mode r] | All modes |
-> [String] | All command line tokens |
-> GlobalLocal g r |