Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- class HasLong o (attr :: [OptAttr]) where
- class HasShort o (attr :: [OptAttr]) where
- class HasHelp o (attr :: [OptAttr]) where
- class HasMetavar o (attr :: [OptAttr]) where
- class HasEnvVar o (attr :: [OptAttr]) where
- class HasDefaultVal o (attr :: [OptAttr]) where
- defaultVal :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultVal" '["defaultStr", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultVal" "optional")) => a -> o attr a -> o (OptDefault ': attr) a
- class HasDefaultStr o (attr :: [OptAttr]) where
- defaultStr :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault ': attr) a
- class HasRequired o (attr :: [OptAttr]) where
- required :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "required" '["defaultVal", "defaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "required" "optional")) => o attr a -> o (OptDefault ': attr) a
- class HasOptional o (attr :: [OptAttr]) where
- optional :: (NotInAttrs OptOptional attr (DuplicateAttrErr "optional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optional" "defaultVal")) => o attr a -> o (OptOptional ': attr) (Maybe a)
- class IsOpt o (attr :: [OptAttr]) where
- option :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b
- flag :: a -> a -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b
- switch :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- switch' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- argument :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b
- parseWith :: (String -> Maybe a) -> String -> Either String a
- readParser :: Read a => OptReader a
- strParser :: IsString s => String -> Either String s
- boolParser :: String -> Either String Bool
- manyParser :: String -> OptReader a -> OptReader [a]
- type QuoteSym (s :: Symbol) = (Text "`" :<>: Text s) :<>: Text "`"
- type family NotInAttrs (x :: k) (xs :: [k]) (err :: ErrorMessage) :: Constraint where ...
- type family CommaSep (xs :: [Symbol]) :: Symbol where ...
- type family CommaSep' (s :: Symbol) (xs :: [Symbol]) :: Symbol where ...
- type DuplicateAttrErr attr = QuoteSym attr :<>: Text " is already specified."
- type DuplicateAttrMultipleErr attr rest = (QuoteSym attr :<>: Text (CommaSep rest)) :<>: Text " has already been specified."
- type IncompatibleAttrsErr l r = ((QuoteSym l :<>: Text " and ") :<>: QuoteSym r) :<>: Text " cannot be mixed in an option definition."
Documentation
class HasHelp o (attr :: [OptAttr]) where Source #
Instances
HasHelp ArgumentOpt a Source # | |
Defined in Options.Harg.Construct help :: String -> ArgumentOpt a a0 -> ArgumentOpt a a0 Source # | |
HasHelp FlagOpt a Source # | |
HasHelp OptionOpt a Source # | |
class HasMetavar o (attr :: [OptAttr]) where Source #
metavar :: String -> o attr a -> o attr a Source #
Add a metavar
metavar to an option, to be
displayed as the meta-parameter next to long/short modifiers
Instances
HasMetavar ArgumentOpt a Source # | |
Defined in Options.Harg.Construct metavar :: String -> ArgumentOpt a a0 -> ArgumentOpt a a0 Source # | |
HasMetavar OptionOpt a Source # | |
class HasEnvVar o (attr :: [OptAttr]) where Source #
envVar :: String -> o attr a -> o attr a Source #
Specify an environment variable to lookup for an option
Instances
HasEnvVar ArgumentOpt a Source # | |
Defined in Options.Harg.Construct envVar :: String -> ArgumentOpt a a0 -> ArgumentOpt a a0 Source # | |
HasEnvVar FlagOpt a Source # | |
HasEnvVar OptionOpt a Source # | |
class HasDefaultVal o (attr :: [OptAttr]) where Source #
defaultVal :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultVal" '["defaultStr", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultVal" "optional")) => a -> o attr a -> o (OptDefault ': attr) a Source #
Add a default value to an option. Cannot be used in conjuction with
with required
, defaultStr
or optional
.
Instances
HasDefaultVal ArgumentOpt a Source # | |
Defined in Options.Harg.Construct defaultVal :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "defaultVal" ("defaultStr" ': ("required" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "defaultVal" "optional")) => a0 -> ArgumentOpt a a0 -> ArgumentOpt (OptDefault ': a) a0 Source # | |
HasDefaultVal OptionOpt a Source # | |
Defined in Options.Harg.Construct defaultVal :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "defaultVal" ("defaultStr" ': ("required" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "defaultVal" "optional")) => a0 -> OptionOpt a a0 -> OptionOpt (OptDefault ': a) a0 Source # |
class HasDefaultStr o (attr :: [OptAttr]) where Source #
defaultStr :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault ': attr) a Source #
Add a default unparsed value to an option. Cannot be used in conjuction
with defaultVal
, required
or optional
.
Instances
HasDefaultStr ArgumentOpt a Source # | |
Defined in Options.Harg.Construct defaultStr :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "defaultStr" ("defaultVal" ': ("required" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "defaultStr" "optional")) => String -> ArgumentOpt a a0 -> ArgumentOpt (OptDefault ': a) a0 Source # | |
HasDefaultStr OptionOpt a Source # | |
Defined in Options.Harg.Construct defaultStr :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "defaultStr" ("defaultVal" ': ("required" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "defaultStr" "optional")) => String -> OptionOpt a a0 -> OptionOpt (OptDefault ': a) a0 Source # |
class HasRequired o (attr :: [OptAttr]) where Source #
required :: (NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "required" '["defaultVal", "defaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "required" "optional")) => o attr a -> o (OptDefault ': attr) a Source #
Mark an option as required. Cannot be used in conjunction with
optional
, defaultVal
or requiredStr
.
Instances
HasRequired ArgumentOpt a Source # | |
Defined in Options.Harg.Construct required :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "required" ("defaultVal" ': ("defaultStr" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "required" "optional")) => ArgumentOpt a a0 -> ArgumentOpt (OptDefault ': a) a0 Source # | |
HasRequired OptionOpt a Source # | |
Defined in Options.Harg.Construct required :: (NotInAttrs OptDefault a (DuplicateAttrMultipleErr "required" ("defaultVal" ': ("defaultStr" ': []))), NotInAttrs OptOptional a (IncompatibleAttrsErr "required" "optional")) => OptionOpt a a0 -> OptionOpt (OptDefault ': a) a0 Source # |
class HasOptional o (attr :: [OptAttr]) where Source #
Class for options that can be optional. Cannot be used in conjunction with
HasDefaultVal
, HasDefaultStr
or HasRequired
. Note that this will turn a
parser for a
into a parser for Maybe a
, modifying the reader function
appropriately.
For example:
someOpt :: Opt (Maybe Int) someOpt = optionWith readParser ( long "someopt" . optional )
optional :: (NotInAttrs OptOptional attr (DuplicateAttrErr "optional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optional" "defaultVal")) => o attr a -> o (OptOptional ': attr) (Maybe a) Source #
Specify that an option is optional. This will convert an Opt a
to an
Opt (Maybe a)
. Cannot be used in conjunction with defaultVal
, defaultStr
or required
.
Instances
HasOptional ArgumentOpt a Source # | |
Defined in Options.Harg.Construct optional :: (NotInAttrs OptOptional a (DuplicateAttrErr "optional"), NotInAttrs OptDefault a (IncompatibleAttrsErr "optional" "defaultVal")) => ArgumentOpt a a0 -> ArgumentOpt (OptOptional ': a) (Maybe a0) Source # | |
HasOptional OptionOpt a Source # | |
Defined in Options.Harg.Construct optional :: (NotInAttrs OptOptional a (DuplicateAttrErr "optional"), NotInAttrs OptDefault a (IncompatibleAttrsErr "optional" "defaultVal")) => OptionOpt a a0 -> OptionOpt (OptOptional ': a) (Maybe a0) Source # |
class IsOpt o (attr :: [OptAttr]) where Source #
Class to convert an intermediate option type into Opt
. Instances
should set the appropriate _optType
.
Create a flag parser, equivalent to option
. The
first argument is the default value (returned when the flag modifier is
absent), and the second is the active value (returned when the flag
modifier is present). The second argument is the modifiers to add to the
option, and can be defined by using function composition (.
).
someFlag :: Opt Int someFlag = flag 0 1 ( long "someflag" . help "Some flag" )
switch :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool Source #
A flag
parser, specialized to Bool
. The parser (e.g. when parsing
an environment variable) will accept true
and false
, but case
insensitive, rather than using the Read
instance for Bool
. The
default value is False
, and the active value is True
.
someSwitch :: Opt Bool someSwitch = switch ( long "someswitch" . help "Some switch" )
argument :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b Source #
readParser :: Read a => OptReader a Source #
A parser that uses the Read
instance to parse into a type.
strParser :: IsString s => String -> Either String s Source #
A parser that returns a string. Any type that has an instance of
IsString
will work, and this parser always succeeds.
boolParser :: String -> Either String Bool Source #
A parser that returns a Bool
. This will succeed for the strings
true
and false
in a case-insensitive manner.
A parser that can parse many items, returning a list.
type QuoteSym (s :: Symbol) = (Text "`" :<>: Text s) :<>: Text "`" Source #
Wrap a symbol in quotes, for pretty printing in type errors.
type family NotInAttrs (x :: k) (xs :: [k]) (err :: ErrorMessage) :: Constraint where ... Source #
Check if x
is not an element of the type-level list xs
. If it is
print the appropriate error message using l
and r
for clarity.
NotInAttrs _ '[] _ = () | |
NotInAttrs x (x ': _) err = TypeError err | |
NotInAttrs x (y ': xs) err = NotInAttrs x xs err |
type family CommaSep (xs :: [Symbol]) :: Symbol where ... Source #
CommaSep '[] = "" | |
CommaSep '[x] = " or " `AppendSymbol` x | |
CommaSep (x ': xs) = " or one of " `AppendSymbol` CommaSep' x xs |
type family CommaSep' (s :: Symbol) (xs :: [Symbol]) :: Symbol where ... Source #
CommaSep' s '[] = s | |
CommaSep' s (x ': xs) = CommaSep' ((s `AppendSymbol` ", ") `AppendSymbol` x) xs |