harg 0.2.0.0 → 0.3.0.0
raw patch · 12 files changed
+338/−423 lines, 12 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Options.Harg: argumentWith :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b
- Options.Harg: flagWith :: a -> a -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b
- Options.Harg: optDefault :: (HasDefault o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefault" '["optDefaultStr", "optRequired"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefault" "optOptional")) => a -> o attr a -> o (OptDefault : attr) a
- Options.Harg: optDefaultStr :: (HasDefaultStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefaultStr" '["optDefault", "optRequired"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefaultStr" "optOptional")) => String -> o attr a -> o (OptDefault : attr) a
- Options.Harg: optEnvVar :: HasEnvVar o attr => String -> o attr a -> o attr a
- Options.Harg: optHelp :: HasHelp o attr => String -> o attr a -> o attr a
- Options.Harg: optLong :: HasLong o attr => String -> o attr a -> o attr a
- Options.Harg: optMetavar :: HasMetavar o attr => String -> o attr a -> o attr a
- Options.Harg: optOptional :: (HasOptional o attr, NotInAttrs OptOptional attr (DuplicateAttrErr "optOptional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optOptional" "optDefault")) => o attr a -> o (OptOptional : attr) (Maybe a)
- Options.Harg: optRequired :: (HasRequired o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optRequired" '["optDefault", "optDefaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optRequired" "optOptional")) => o attr a -> o (OptDefault : attr) a
- Options.Harg: optShort :: HasShort o attr => Char -> o attr a -> o attr a
- Options.Harg: optionWith :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b
- Options.Harg: switchWith :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg: switchWith' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg.Construct: argumentWith :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b
- Options.Harg.Construct: class HasDefault o (attr :: [OptAttr])
- Options.Harg.Construct: class HasDefaultStr o (attr :: [OptAttr])
- Options.Harg.Construct: flagWith :: a -> a -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefault Options.Harg.Types.ArgumentOpt a
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefault Options.Harg.Types.OptionOpt a
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultStr Options.Harg.Types.ArgumentOpt a
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultStr Options.Harg.Types.OptionOpt a
- Options.Harg.Construct: optDefault :: (HasDefault o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefault" '["optDefaultStr", "optRequired"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefault" "optOptional")) => a -> o attr a -> o (OptDefault : attr) a
- Options.Harg.Construct: optDefaultStr :: (HasDefaultStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefaultStr" '["optDefault", "optRequired"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefaultStr" "optOptional")) => String -> o attr a -> o (OptDefault : attr) a
- Options.Harg.Construct: optEnvVar :: HasEnvVar o attr => String -> o attr a -> o attr a
- Options.Harg.Construct: optHelp :: HasHelp o attr => String -> o attr a -> o attr a
- Options.Harg.Construct: optLong :: HasLong o attr => String -> o attr a -> o attr a
- Options.Harg.Construct: optMetavar :: HasMetavar o attr => String -> o attr a -> o attr a
- Options.Harg.Construct: optOptional :: (HasOptional o attr, NotInAttrs OptOptional attr (DuplicateAttrErr "optOptional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optOptional" "optDefault")) => o attr a -> o (OptOptional : attr) (Maybe a)
- Options.Harg.Construct: optRequired :: (HasRequired o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optRequired" '["optDefault", "optDefaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "optRequired" "optOptional")) => o attr a -> o (OptDefault : attr) a
- Options.Harg.Construct: optShort :: HasShort o attr => Char -> o attr a -> o attr a
- Options.Harg.Construct: optionWith :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b
- Options.Harg.Construct: switchWith :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg.Construct: switchWith' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg.Types: [_aDefault] :: ArgumentOpt a -> Maybe a
- Options.Harg.Types: [_fDefault] :: FlagOpt a -> a
- Options.Harg.Types: [_oDefault] :: OptionOpt a -> Maybe a
- Options.Harg.Types: [_optDefault] :: Opt a -> Maybe a
+ Options.Harg: defaultStr :: (HasDefaultValStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
+ Options.Harg: defaultVal :: (HasDefaultVal o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultVal" '["defaultStr", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultVal" "optional")) => a -> o attr a -> o (OptDefault : attr) a
+ Options.Harg: envVar :: HasEnvVar o attr => String -> o attr a -> o attr a
+ Options.Harg: help :: HasHelp o attr => String -> o attr a -> o attr a
+ Options.Harg: long :: HasLong o attr => String -> o attr a -> o attr a
+ Options.Harg: metavar :: HasMetavar o attr => String -> o attr a -> o attr a
+ Options.Harg: optional :: (HasOptional o attr, NotInAttrs OptOptional attr (DuplicateAttrErr "optional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optional" "defaultVal")) => o attr a -> o (OptOptional : attr) (Maybe a)
+ Options.Harg: required :: (HasRequired o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "required" '["defaultVal", "defaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "required" "optional")) => o attr a -> o (OptDefault : attr) a
+ Options.Harg: short :: HasShort o attr => Char -> o attr a -> o attr a
+ Options.Harg.Construct: class HasDefaultVal o (attr :: [OptAttr])
+ Options.Harg.Construct: class HasDefaultValStr o (attr :: [OptAttr])
+ Options.Harg.Construct: defaultStr :: (HasDefaultValStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
+ Options.Harg.Construct: defaultVal :: (HasDefaultVal o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultVal" '["defaultStr", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultVal" "optional")) => a -> o attr a -> o (OptDefault : attr) a
+ Options.Harg.Construct: envVar :: HasEnvVar o attr => String -> o attr a -> o attr a
+ Options.Harg.Construct: help :: HasHelp o attr => String -> o attr a -> o attr a
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultVal Options.Harg.Types.ArgumentOpt a
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultVal Options.Harg.Types.OptionOpt a
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultValStr Options.Harg.Types.ArgumentOpt a
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultValStr Options.Harg.Types.OptionOpt a
+ Options.Harg.Construct: long :: HasLong o attr => String -> o attr a -> o attr a
+ Options.Harg.Construct: metavar :: HasMetavar o attr => String -> o attr a -> o attr a
+ Options.Harg.Construct: optional :: (HasOptional o attr, NotInAttrs OptOptional attr (DuplicateAttrErr "optional"), NotInAttrs OptDefault attr (IncompatibleAttrsErr "optional" "defaultVal")) => o attr a -> o (OptOptional : attr) (Maybe a)
+ Options.Harg.Construct: required :: (HasRequired o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "required" '["defaultVal", "defaultStr"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "required" "optional")) => o attr a -> o (OptDefault : attr) a
+ Options.Harg.Construct: short :: HasShort o attr => Char -> o attr a -> o attr a
+ Options.Harg.Types: [_aDefaultVal] :: ArgumentOpt a -> Maybe a
+ Options.Harg.Types: [_fDefaultVal] :: FlagOpt a -> a
+ Options.Harg.Types: [_oDefaultVal] :: OptionOpt a -> Maybe a
+ Options.Harg.Types: [_optDefaultVal] :: Opt a -> Maybe a
- Options.Harg: argument :: OptReader a -> ArgumentOpt '[] a
+ Options.Harg: argument :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b
- Options.Harg: flag :: a -> a -> FlagOpt '[] a
+ Options.Harg: flag :: a -> a -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b
- Options.Harg: option :: OptReader a -> OptionOpt '[] a
+ Options.Harg: option :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b
- Options.Harg: switch :: FlagOpt '[] Bool
+ Options.Harg: switch :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg: switch' :: FlagOpt '[] Bool
+ Options.Harg: switch' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg.Construct: argument :: OptReader a -> ArgumentOpt '[] a
+ Options.Harg.Construct: argument :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b
- Options.Harg.Construct: flag :: a -> a -> FlagOpt '[] a
+ Options.Harg.Construct: flag :: a -> a -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b
- Options.Harg.Construct: option :: OptReader a -> OptionOpt '[] a
+ Options.Harg.Construct: option :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b
- Options.Harg.Construct: switch :: FlagOpt '[] Bool
+ Options.Harg.Construct: switch :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
- Options.Harg.Construct: switch' :: FlagOpt '[] Bool
+ Options.Harg.Construct: switch' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool
Files
- CHANGELOG.md +12/−2
- README.lhs +75/−91
- README.md +75/−91
- harg.cabal +1/−1
- src/Options/Harg.hs +24/−27
- src/Options/Harg/Cmdline.hs +3/−3
- src/Options/Harg/Construct.hs +128/−190
- src/Options/Harg/Sources/JSON.hs +1/−1
- src/Options/Harg/Sources/Types.hs +4/−4
- src/Options/Harg/Sources/YAML.hs +1/−1
- src/Options/Harg/Types.hs +10/−10
- src/Options/Harg/Util.hs +4/−2
CHANGELOG.md view
@@ -1,8 +1,18 @@ # Changelog for harg +## 0.3.0.0 [2019.09.16]++- Remove `*With` variants of option constructors and make the `*With` variant behaviour the default+ (meaning now options are constructed using function composition and not `toOpt`)+- Remove `opt` prefix from modifiers. Because `default` is a reserved keyword, this is now named+ `defaultVal` (to mirror `defaultStr`)++ NOTE: the above introduce breaking changes+ ## 0.2.0.0 [2019.09.06] - Trigger a parser failure when any option in the sources fails to parse+ NOTE: this introduces a breaking change, in that some parsers that failed silently and selected the default (if applicable) will now fail. @@ -12,11 +22,11 @@ ## 0.1.2.0 [2019.08.19] -- Add `optRequired` to mark option as required+- Add `optRequired` (renamed to `required` for 0.3.0.0) to mark option as required ## 0.1.1.0 [2019.08.16] -- Add `optDefaultStr` to provide defaults as unparsed strings+- Add `optDefaultStr` (renamed to `defaultStr` for 0.3.0.0) to provide defaults as unparsed strings - Bump dependencies (`barbies` and `higgledy`) ## 0.1.0.1 [2019.07.19]
README.lhs view
@@ -32,7 +32,6 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} -import Data.Function ((&)) import Data.Functor.Identity (Identity (..)) import Data.Kind (Type) import GHC.Generics (Generic)@@ -71,62 +70,47 @@ ``` haskell dbHostOpt :: Opt String dbHostOpt- = toOpt ( option strParser- & optLong "host"- & optShort 'h'- & optMetavar "DB_HOST"- & optHelp "The database host"- )+ = option strParser+ ( long "host"+ . short 'h'+ . metavar "DB_HOST"+ . help "The database host"+ ) dbPortOpt :: Opt Int dbPortOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The database port"- & optEnvVar "DB_PORT"- & optDefault 5432- )+ = option readParser+ ( long "port"+ . help "The database port"+ . envVar "DB_PORT"+ . defaultVal 5432+ ) dirOpt :: Opt String dirOpt- = toOpt ( argument strParser- & optHelp "Some directory"- & optDefault "/home/user/something"- )+ = argument strParser+ ( help "Some directory"+ . defaultVal "/home/user/something"+ ) logOpt :: Opt Bool logOpt- = toOpt ( switch- & optLong "log"- & optHelp "Whether to log or not"- )+ = switch+ ( long "log"+ . help "Whether to log or not"+ ) ``` Here, we use `option` to define a command line argument that expects a value after it, `argument` to define a standalone argument, not prefixed by a long or short indicator, and `switch` to define a boolean command line flag that, if present, sets the target value to `True`. The `opt*` functions (here applied using `&` to make things look more declarative) modify the option configuration.-`optHelp` adds help text, `optDefault` adds a default value, `optShort` adds a short command line-option as an alternative to the long one (the string after `option` or `switch`), `optEnvVar` sets-the associated environment variable and `optMetavar` sets the metavariable to be shown in the help+`help` adds help text, `defaultVal` adds a default value, `short` adds a short command line+option as an alternative to the long one (the string after `option` or `switch`), `envVar` sets+the associated environment variable and `metavar` sets the metavariable to be shown in the help text generated by `optparse-applicative`. -`toOpt` turns any kind of option into the internal `Opt` type. The reason for doing this is that-different types of options can have different capabilities, e.g. `long` and `short` cannot be set-for an `argument`. Another shorthand is to use the `with` variants. For example, `dbHostOpt` could-also be defined like this: -``` haskell-dbHostOpt' :: Opt String-dbHostOpt'- = optionWith strParser- ( optLong "host"- . optShort 'h'- . optMetavar "DB_HOST"- . optHelp "The database host"- )-```- The first argument (`strParser` or `readParser`) is the parser for the argument, be it from the command line or from an environment variable. The type of this function should be `String -> Either String a`, which produces an error message or the parsed value. `strParser` is@@ -151,20 +135,20 @@ message. For example, `readParser` is defined as `parseWith readMaybe`. Finally, an optional option with type `a` can be specified by setting its type to `Maybe a`. The-declaration is exactly the same as it would be for `a`, and adding `optOptional` to the modifiers+declaration is exactly the same as it would be for `a`, and adding `optional` to the modifiers turns turns the parser from `String -> Either String a` to `String -> Either String (Maybe a)` but without using the `Read` instance for `Maybe`: ``` haskell ignore someOpt :: Opt (Maybe Int) someOpt- = toOpt ( option readParser- & optLong "something"- & optOptional- )+ = option readParser+ ( long "something"+ . optional+ ) ``` -Note that `optOptional` can't be used with `optDefault`. Using them together raises a type error at+Note that `optional` can't be used with `defaultVal`. Using them together raises a type error at compile time, to ensure there's no ambiguous behaviour (e.g. the order of declaration of modifiers should not influence the resulting option). @@ -322,11 +306,11 @@ ``` haskell portOpt :: Opt Int portOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The service port"- & optDefault 8080- )+ = option readParser+ ( long "port"+ . help "The service port"+ . defaultVal 8080+ ) ``` Again, there are several ways to configure these options.@@ -540,19 +524,19 @@ fooOpt :: Opt String fooOpt- = toOpt ( option strParser- & optShort 'f'- & optHelp "Something foo"- & optDefault "this is the default foo"- )+ = option strParser+ ( short 'f'+ . help "Something foo"+ . defaultVal "this is the default foo"+ ) barOpt :: Opt Int barOpt- = toOpt ( option readParser- & optShort 'b'- & optHelp "Something bar"- & optDefault 42- )+ = option readParser+ ( short 'b'+ . help "Something bar"+ . defaultVal 42+ ) type TestConfigP = Single String :* Single Int@@ -655,35 +639,35 @@ dbHostOpt :: Opt String dbHostOpt- = toOpt ( option strParser- & optLong "host"- & optShort 'h'- & optMetavar "DB_HOST"- & optHelp "The database host"- )+ = option strParser+ ( long "host"+ . short 'h'+ . metavar "DB_HOST"+ . help "The database host"+ ) dbPortOpt :: Opt Int dbPortOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The database port"- & optEnvVar "DB_PORT"- & optDefault 5432- )+ = option readParser+ ( long "port"+ . help "The database port"+ . envVar "DB_PORT"+ . defaultVal 5432+ ) dirOpt :: Opt String dirOpt- = toOpt ( argument strParser- & optHelp "Some directory"- & optDefault "/home/user/something"- )+ = argument strParser+ ( help "Some directory"+ . defaultVal "/home/user/something"+ ) logOpt :: Opt Bool logOpt- = toOpt ( switch- & optLong "log"- & optHelp "Whether to log or not"- )+ = switch+ ( long "log"+ . help "Whether to log or not"+ ) flatConfigOpt3 :: HKD FlatConfig Opt flatConfigOpt3@@ -717,11 +701,11 @@ where jsonOpt :: Opt ConfigFile jsonOpt- = toOpt ( option strParser- & optLong "json"- & optShort 'j'- & optHelp "JSON config filepath"- )+ = option strParser+ ( long "json"+ . short 'j'+ . help "JSON config filepath"+ ) ``` Here, the type of the option for the JSON source is `ConfigFile`. This type is a wrapper around@@ -739,17 +723,17 @@ ``` haskell jsonOpt :: Opt ConfigFile jsonOpt- = toOpt ( option strParser- & optLong "json"- & optDefault NoConfigFile- )+ = option strParser+ ( long "json"+ . defaultVal NoConfigFile+ ) ``` Also, because `ConfigFile` has an `IsString` instance, there's no need to say-`optLong (ConfigFile "json")` (if `OverloadedStrings` is enabled).+`long (ConfigFile "json")` (if `OverloadedStrings` is enabled). There's a bit of a disconnect between `ConfigFile` and the ability to make optional options using-`Maybe` and `optOptional`. The reason for it is that the type that `JSONSource` wraps is not+`Maybe` and `optional`. The reason for it is that the type that `JSONSource` wraps is not polymorphic, since it needs to be a filepath specifically. # Roadmap
README.md view
@@ -32,7 +32,6 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} -import Data.Function ((&)) import Data.Functor.Identity (Identity (..)) import Data.Kind (Type) import GHC.Generics (Generic)@@ -71,62 +70,47 @@ ``` haskell dbHostOpt :: Opt String dbHostOpt- = toOpt ( option strParser- & optLong "host"- & optShort 'h'- & optMetavar "DB_HOST"- & optHelp "The database host"- )+ = option strParser+ ( long "host"+ . short 'h'+ . metavar "DB_HOST"+ . help "The database host"+ ) dbPortOpt :: Opt Int dbPortOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The database port"- & optEnvVar "DB_PORT"- & optDefault 5432- )+ = option readParser+ ( long "port"+ . help "The database port"+ . envVar "DB_PORT"+ . defaultVal 5432+ ) dirOpt :: Opt String dirOpt- = toOpt ( argument strParser- & optHelp "Some directory"- & optDefault "/home/user/something"- )+ = argument strParser+ ( help "Some directory"+ . defaultVal "/home/user/something"+ ) logOpt :: Opt Bool logOpt- = toOpt ( switch- & optLong "log"- & optHelp "Whether to log or not"- )+ = switch+ ( long "log"+ . help "Whether to log or not"+ ) ``` Here, we use `option` to define a command line argument that expects a value after it, `argument` to define a standalone argument, not prefixed by a long or short indicator, and `switch` to define a boolean command line flag that, if present, sets the target value to `True`. The `opt*` functions (here applied using `&` to make things look more declarative) modify the option configuration.-`optHelp` adds help text, `optDefault` adds a default value, `optShort` adds a short command line-option as an alternative to the long one (the string after `option` or `switch`), `optEnvVar` sets-the associated environment variable and `optMetavar` sets the metavariable to be shown in the help+`help` adds help text, `defaultVal` adds a default value, `short` adds a short command line+option as an alternative to the long one (the string after `option` or `switch`), `envVar` sets+the associated environment variable and `metavar` sets the metavariable to be shown in the help text generated by `optparse-applicative`. -`toOpt` turns any kind of option into the internal `Opt` type. The reason for doing this is that-different types of options can have different capabilities, e.g. `long` and `short` cannot be set-for an `argument`. Another shorthand is to use the `with` variants. For example, `dbHostOpt` could-also be defined like this: -``` haskell-dbHostOpt' :: Opt String-dbHostOpt'- = optionWith strParser- ( optLong "host"- . optShort 'h'- . optMetavar "DB_HOST"- . optHelp "The database host"- )-```- The first argument (`strParser` or `readParser`) is the parser for the argument, be it from the command line or from an environment variable. The type of this function should be `String -> Either String a`, which produces an error message or the parsed value. `strParser` is@@ -151,20 +135,20 @@ message. For example, `readParser` is defined as `parseWith readMaybe`. Finally, an optional option with type `a` can be specified by setting its type to `Maybe a`. The-declaration is exactly the same as it would be for `a`, and adding `optOptional` to the modifiers+declaration is exactly the same as it would be for `a`, and adding `optional` to the modifiers turns turns the parser from `String -> Either String a` to `String -> Either String (Maybe a)` but without using the `Read` instance for `Maybe`: ``` haskell ignore someOpt :: Opt (Maybe Int) someOpt- = toOpt ( option readParser- & optLong "something"- & optOptional- )+ = option readParser+ ( long "something"+ . optional+ ) ``` -Note that `optOptional` can't be used with `optDefault`. Using them together raises a type error at+Note that `optional` can't be used with `defaultVal`. Using them together raises a type error at compile time, to ensure there's no ambiguous behaviour (e.g. the order of declaration of modifiers should not influence the resulting option). @@ -322,11 +306,11 @@ ``` haskell portOpt :: Opt Int portOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The service port"- & optDefault 8080- )+ = option readParser+ ( long "port"+ . help "The service port"+ . defaultVal 8080+ ) ``` Again, there are several ways to configure these options.@@ -540,19 +524,19 @@ fooOpt :: Opt String fooOpt- = toOpt ( option strParser- & optShort 'f'- & optHelp "Something foo"- & optDefault "this is the default foo"- )+ = option strParser+ ( short 'f'+ . help "Something foo"+ . defaultVal "this is the default foo"+ ) barOpt :: Opt Int barOpt- = toOpt ( option readParser- & optShort 'b'- & optHelp "Something bar"- & optDefault 42- )+ = option readParser+ ( short 'b'+ . help "Something bar"+ . defaultVal 42+ ) type TestConfigP = Single String :* Single Int@@ -655,35 +639,35 @@ dbHostOpt :: Opt String dbHostOpt- = toOpt ( option strParser- & optLong "host"- & optShort 'h'- & optMetavar "DB_HOST"- & optHelp "The database host"- )+ = option strParser+ ( long "host"+ . short 'h'+ . metavar "DB_HOST"+ . help "The database host"+ ) dbPortOpt :: Opt Int dbPortOpt- = toOpt ( option readParser- & optLong "port"- & optHelp "The database port"- & optEnvVar "DB_PORT"- & optDefault 5432- )+ = option readParser+ ( long "port"+ . help "The database port"+ . envVar "DB_PORT"+ . defaultVal 5432+ ) dirOpt :: Opt String dirOpt- = toOpt ( argument strParser- & optHelp "Some directory"- & optDefault "/home/user/something"- )+ = argument strParser+ ( help "Some directory"+ . defaultVal "/home/user/something"+ ) logOpt :: Opt Bool logOpt- = toOpt ( switch- & optLong "log"- & optHelp "Whether to log or not"- )+ = switch+ ( long "log"+ . help "Whether to log or not"+ ) flatConfigOpt3 :: HKD FlatConfig Opt flatConfigOpt3@@ -717,11 +701,11 @@ where jsonOpt :: Opt ConfigFile jsonOpt- = toOpt ( option strParser- & optLong "json"- & optShort 'j'- & optHelp "JSON config filepath"- )+ = option strParser+ ( long "json"+ . short 'j'+ . help "JSON config filepath"+ ) ``` Here, the type of the option for the JSON source is `ConfigFile`. This type is a wrapper around@@ -739,17 +723,17 @@ ``` haskell jsonOpt :: Opt ConfigFile jsonOpt- = toOpt ( option strParser- & optLong "json"- & optDefault NoConfigFile- )+ = option strParser+ ( long "json"+ . defaultVal NoConfigFile+ ) ``` Also, because `ConfigFile` has an `IsString` instance, there's no need to say-`optLong (ConfigFile "json")` (if `OverloadedStrings` is enabled).+`long (ConfigFile "json")` (if `OverloadedStrings` is enabled). There's a bit of a disconnect between `ConfigFile` and the ability to make optional options using-`Maybe` and `optOptional`. The reason for it is that the type that `JSONSource` wraps is not+`Maybe` and `optional`. The reason for it is that the type that `JSONSource` wraps is not polymorphic, since it needs to be a filepath specifically. # Roadmap
harg.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: harg-version: 0.2.0.0+version: 0.3.0.0 synopsis: Haskell program configuration using higher kinded data description: Please see the README on GitHub at <https://github.com/alexpeits/harg#readme> homepage: https://github.com/alexpeits/harg
src/Options/Harg.hs view
@@ -5,15 +5,10 @@ -- ** Option declaration option- , optionWith , flag- , flagWith , switch- , switchWith , switch'- , switchWith' , argument- , argumentWith , Single (..) , single@@ -31,15 +26,15 @@ , Tagged (..) -- ** Option modifiers- , optLong- , optShort- , optHelp- , optMetavar- , optEnvVar- , optDefault- , optDefaultStr- , optRequired- , optOptional+ , long+ , short+ , help+ , metavar+ , envVar+ , defaultVal+ , defaultStr+ , required+ , optional , toOpt , Opt @@ -80,10 +75,12 @@ , pattern In5 -- ** Re-exports+ -- *** barbies , B.FunctorB , B.TraversableB , B.ProductB + -- *** higgledy , HKD.HKD , HKD.build , HKD.construct@@ -132,28 +129,28 @@ -- where -- hostOpt -- = optionWith strParser--- ( optLong \"host\"--- . optShort \'h\'--- . optHelp \"Hostname\"--- . optEnvVar \"HOST_NAME\"+-- ( long \"host\"+-- . short \'h\'+-- . help \"Hostname\"+-- . envVar \"HOST_NAME\" -- ) -- portOpt -- = optionWith readParser--- ( optLong \"port\"--- . optShort \'p\'--- . optHelp \"Port number\"--- . optDefault 5432+-- ( long \"port\"+-- . short \'p\'+-- . help \"Port number\"+-- . defaultVal 5432 -- ) -- logOpt -- = switchWith--- ( optLong \"log\"--- . optHelp \"Whether to log or not\"+-- ( long \"log\"+-- . help \"Whether to log or not\" -- ) -- dirOpt -- = argumentWith strParser--- ( optHelp \"Some directory\"--- . optEnvVar \"SOME_DIR\"--- . optOptional+-- ( help \"Some directory\"+-- . envVar \"SOME_DIR\"+-- . optional -- ) -- -- main :: IO Config
src/Options/Harg/Cmdline.hs view
@@ -58,7 +58,7 @@ , Optparse.short <$> _optShort , Optparse.help <$> ppHelp opt , Optparse.metavar <$> _optMetavar- , Optparse.value <$> (getCompose sources <|> _optDefault)+ , Optparse.value <$> (getCompose sources <|> _optDefaultVal) ] ) @@ -79,7 +79,7 @@ where mDef = case getCompose sources of- Nothing -> _optDefault+ Nothing -> _optDefaultVal Just x -> Just x modifiers = foldMap (fromMaybe mempty)@@ -99,6 +99,6 @@ ( foldMap (fromMaybe mempty) [ Optparse.help <$> ppHelp opt , Optparse.metavar <$> _optMetavar- , Optparse.value <$> (getCompose sources <|> _optDefault)+ , Optparse.value <$> (getCompose sources <|> _optDefaultVal) ] )
src/Options/Harg/Construct.hs view
@@ -17,108 +17,108 @@ class HasLong o (attr :: [OptAttr]) where -- | Add a 'Options.Applicative.long' modifier to an option- optLong :: String -> o attr a -> o attr a+ long :: String -> o attr a -> o attr a instance HasLong OptionOpt a where- optLong s o = o { _oLong = Just s }+ long s o = o { _oLong = Just s } instance HasLong FlagOpt a where- optLong s o = o { _fLong = Just s }+ long s o = o { _fLong = Just s } class HasShort o (attr :: [OptAttr]) where -- | Add a 'Options.Applicative.short' modifier to an option- optShort :: Char -> o attr a -> o attr a+ short :: Char -> o attr a -> o attr a instance HasShort OptionOpt a where- optShort c o = o { _oShort = Just c }+ short c o = o { _oShort = Just c } instance HasShort FlagOpt a where- optShort c o = o { _fShort = Just c }+ short c o = o { _fShort = Just c } class HasHelp o (attr :: [OptAttr]) where -- | Add 'Options.Applicative.help' to an option- optHelp :: String -> o attr a -> o attr a+ help :: String -> o attr a -> o attr a instance HasHelp OptionOpt a where- optHelp s o = o { _oHelp = Just s }+ help s o = o { _oHelp = Just s } instance HasHelp FlagOpt a where- optHelp s o = o { _fHelp = Just s }+ help s o = o { _fHelp = Just s } instance HasHelp ArgumentOpt a where- optHelp s o = o { _aHelp = Just s }+ help s o = o { _aHelp = Just s } class HasMetavar o (attr :: [OptAttr]) where -- | Add a 'Options.Applicative.metavar' metavar to an option, to be -- displayed as the meta-parameter next to long/short modifiers- optMetavar :: String -> o attr a -> o attr a+ metavar :: String -> o attr a -> o attr a instance HasMetavar OptionOpt a where- optMetavar s o = o { _oMetavar = Just s }+ metavar s o = o { _oMetavar = Just s } instance HasMetavar ArgumentOpt a where- optMetavar s o = o { _aMetavar = Just s }+ metavar s o = o { _aMetavar = Just s } class HasEnvVar o (attr :: [OptAttr]) where -- | Specify an environment variable to lookup for an option- optEnvVar :: String -> o attr a -> o attr a+ envVar :: String -> o attr a -> o attr a instance HasEnvVar OptionOpt a where- optEnvVar s o = o { _oEnvVar = Just s }+ envVar s o = o { _oEnvVar = Just s } instance HasEnvVar FlagOpt a where- optEnvVar s o = o { _fEnvVar = Just s }+ envVar s o = o { _fEnvVar = Just s } instance HasEnvVar ArgumentOpt a where- optEnvVar s o = o { _aEnvVar = Just s }+ envVar s o = o { _aEnvVar = Just s } -class HasDefault o (attr :: [OptAttr]) where+class HasDefaultVal o (attr :: [OptAttr]) where -- | Add a default value to an option. Cannot be used in conjuction with- -- with 'optRequired', 'optDefaultStr' or 'optOptional'.- optDefault- :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefault" '["optDefaultStr", "optRequired"])- , NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefault" "optOptional")+ -- with 'required', 'defaultStr' or 'optional'.+ defaultVal+ :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultVal" '["defaultStr", "required"])+ , NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultVal" "optional") ) => a -> o attr a -> o (OptDefault ': attr) a -instance HasDefault OptionOpt a where- optDefault a o = o { _oDefault = Just a }+instance HasDefaultVal OptionOpt a where+ defaultVal a o = o { _oDefaultVal = Just a } -instance HasDefault ArgumentOpt a where- optDefault a o = o { _aDefault = Just a }+instance HasDefaultVal ArgumentOpt a where+ defaultVal a o = o { _aDefaultVal = Just a } -class HasDefaultStr o (attr :: [OptAttr]) where+class HasDefaultValStr o (attr :: [OptAttr]) where -- | Add a default unparsed value to an option. Cannot be used in conjuction- -- with 'optDefault', 'optRequired' or 'optOptional'.- optDefaultStr- :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optDefaultStr" '["optDefault", "optRequired"])- , NotInAttrs OptOptional attr (IncompatibleAttrsErr "optDefaultStr" "optOptional")+ -- with 'defaultVal', 'required' or 'optional'.+ defaultStr+ :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"])+ , NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional") ) => String -> o attr a -> o (OptDefault ': attr) a -instance HasDefaultStr OptionOpt a where- optDefaultStr s o = o { _oDefaultStr = Just s }+instance HasDefaultValStr OptionOpt a where+ defaultStr s o = o { _oDefaultStr = Just s } -instance HasDefaultStr ArgumentOpt a where- optDefaultStr s o = o { _aDefaultStr = Just s }+instance HasDefaultValStr ArgumentOpt a where+ defaultStr s o = o { _aDefaultStr = Just s } class HasRequired o (attr :: [OptAttr]) where -- | Mark an option as required. Cannot be used in conjunction with- -- 'optOptional', 'optDefault' or 'optRequiredStr'.- optRequired- :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "optRequired" '["optDefault", "optDefaultStr"])- , NotInAttrs OptOptional attr (IncompatibleAttrsErr "optRequired" "optOptional")+ -- 'optional', 'defaultVal' or 'requiredStr'.+ required+ :: ( NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "required" '["defaultVal", "defaultStr"])+ , NotInAttrs OptOptional attr (IncompatibleAttrsErr "required" "optional") ) => o attr a -> o (OptDefault ': attr) a instance HasRequired OptionOpt a where- optRequired o = o { _oDefault = Nothing }+ required o = o { _oDefaultVal = Nothing } instance HasRequired ArgumentOpt a where- optRequired o = o { _aDefault = Nothing }+ required o = o { _aDefaultVal = Nothing } -- | Class for options that can be optional. Cannot be used in conjunction with--- 'HasDefault', 'HasDefaultStr' or 'HasRequired'. Note that this will turn a+-- 'HasDefaultVal', 'HasDefaultValStr' or 'HasRequired'. Note that this will turn a -- parser for @a@ into a parser for @Maybe a@, modifying the reader function -- appropriately. -- For example:@@ -127,40 +127,40 @@ -- someOpt :: Opt (Maybe Int) -- someOpt -- = optionWith readParser--- ( optLong "someopt"--- . optOptional+-- ( long "someopt"+-- . optional -- ) -- @ class HasOptional o (attr :: [OptAttr]) where -- | Specify that an option is optional. This will convert an @Opt a@ to an- -- @Opt (Maybe a)@. Cannot be used in conjunction with 'optDefault', 'optDefaultStr'- -- or 'optRequired'.- optOptional- :: ( NotInAttrs OptOptional attr (DuplicateAttrErr "optOptional")- , NotInAttrs OptDefault attr (IncompatibleAttrsErr "optOptional" "optDefault")+ -- @Opt (Maybe a)@. Cannot be used in conjunction with 'defaultVal', 'defaultStr'+ -- or 'required'.+ optional+ :: ( NotInAttrs OptOptional attr (DuplicateAttrErr "optional")+ , NotInAttrs OptDefault attr (IncompatibleAttrsErr "optional" "defaultVal") ) => o attr a -> o (OptOptional ': attr) (Maybe a) instance HasOptional OptionOpt a where- optOptional OptionOpt{..}+ optional OptionOpt{..} = OptionOpt { _oLong = _oLong , _oShort = _oShort , _oHelp = _oHelp , _oMetavar = _oMetavar , _oEnvVar = _oEnvVar- , _oDefault = Just Nothing+ , _oDefaultVal = Just Nothing , _oDefaultStr = Nothing , _oReader = fmap Just . _oReader } instance HasOptional ArgumentOpt a where- optOptional ArgumentOpt{..}+ optional ArgumentOpt{..} = ArgumentOpt { _aHelp = _aHelp , _aMetavar = _aMetavar , _aEnvVar = _aEnvVar- , _aDefault = Just Nothing+ , _aDefaultVal = Just Nothing , _aDefaultStr = Nothing , _aReader = fmap Just . _aReader }@@ -179,7 +179,7 @@ , _optHelp = _oHelp , _optMetavar = _oMetavar , _optEnvVar = _oEnvVar- , _optDefault = _oDefault+ , _optDefaultVal = _oDefaultVal , _optDefaultStr = _oDefaultStr , _optReader = _oReader , _optType = OptionOptType@@ -193,7 +193,7 @@ , _optHelp = _fHelp , _optMetavar = Nothing , _optEnvVar = _fEnvVar- , _optDefault = Just _fDefault+ , _optDefaultVal = Just _fDefaultVal , _optDefaultStr = Nothing , _optReader = _fReader , _optType = FlagOptType _fActive@@ -207,105 +207,76 @@ , _optHelp = _aHelp , _optMetavar = _aMetavar , _optEnvVar = _aEnvVar- , _optDefault = _aDefault+ , _optDefaultVal = _aDefaultVal , _optDefaultStr = _aDefaultStr , _optReader = _aReader , _optType = ArgumentOptType } -- | Create an option parser, equivalent to 'Options.Applicative.option'. The--- result can then be used with 'toOpt' to convert into the global 'Opt' type.------ @--- someOption :: Opt Int--- someOption--- = toOpt ( option readParser--- & optLong "someopt"--- & optHelp "Some option"--- & optDefault 256--- )--- @-option- :: OptReader a- -> OptionOpt '[] a-option p- = OptionOpt- { _oLong = Nothing- , _oShort = Nothing- , _oHelp = Nothing- , _oMetavar = Nothing- , _oEnvVar = Nothing- , _oDefault = Nothing- , _oDefaultStr = Nothing- , _oReader = p- }---- | Similar to 'option', but accepts a modifier function and returns an 'Opt'--- directly.+-- second argument is the modifiers to add to the option, and can be defined by+-- using function composition ('.'). -- -- @ -- someOption :: Opt Int -- someOption--- = optionWith readParser--- ( optLong "someopt"--- . optHelp "Some option"--- . optDefault 256+-- = option readParser+-- ( long "someopt"+-- . help "Some option"+-- . defaultVal 256 -- ) -- @-optionWith+option :: OptReader a -> (OptionOpt '[] a -> OptionOpt attr b) -> Opt b-optionWith p f- = toOpt $ f (option p)+option p f+ = toOpt $ f opt+ where+ opt+ = OptionOpt+ { _oLong = Nothing+ , _oShort = Nothing+ , _oHelp = Nothing+ , _oMetavar = Nothing+ , _oEnvVar = Nothing+ , _oDefaultVal = Nothing+ , _oDefaultStr = Nothing+ , _oReader = p+ } -- | Create a flag parser, equivalent to 'Options.Applicative.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 result can then be used with 'toOpt' to convert--- into the global 'Opt' type.------ @--- someFlag :: Opt Int--- someFlag--- = toOpt ( flag 0 1--- & optLong "someflag"--- & optHelp "Some flag"--- )--- @-flag- :: a -- ^ Default value- -> a -- ^ Active value- -> FlagOpt '[] a-flag d active- = FlagOpt- { _fLong = Nothing- , _fShort = Nothing- , _fHelp = Nothing- , _fEnvVar = Nothing- , _fDefault = d- , _fActive = active- , _fReader = const (pure d) -- TODO- }---- | Similar to 'flag', but accepts a modifier function and returns an 'Opt'--- directly.+-- 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--- = flagWith 0 1--- ( optLong "someflag"--- . optHelp "Some flag"+-- = flag 0 1+-- ( long "someflag"+-- . help "Some flag" -- ) -- @-flagWith+flag :: a -- ^ Default value -> a -- ^ Active value -> (FlagOpt '[] a -> FlagOpt attr b) -> Opt b-flagWith d active f- = toOpt $ f (flag d active)+flag d active f+ = toOpt $ f opt+ where+ opt+ = FlagOpt+ { _fLong = Nothing+ , _fShort = Nothing+ , _fHelp = Nothing+ , _fEnvVar = Nothing+ , _fDefaultVal = d+ , _fActive = active+ , _fReader = const (pure d) -- TODO+ } -- | A 'flag' parser, specialized to 'Bool'. The parser (e.g. when parsing -- an environment variable) will accept @true@ and @false@, but case@@ -315,92 +286,59 @@ -- @ -- someSwitch :: Opt Bool -- someSwitch--- = toOpt ( switch--- & optLong "someswitch"--- & optHelp "Some switch"--- )--- @-switch :: FlagOpt '[] Bool-switch- = fl { _fReader = boolParser }- where- fl = flag False True---- | Similar to 'switch', but accepts a modifier function and returns an 'Opt'--- directly.------ @--- someSwitch :: Opt Bool--- someSwitch--- = switchWith--- ( optLong "someswitch"--- . optHelp "Some switch"+-- = switch+-- ( long "someswitch"+-- . help "Some switch" -- ) -- @-switchWith+switch :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool-switchWith f- = toOpt $ f switch+switch f+ = fl { _optReader = boolParser }+ where+ fl+ = flag False True f -- | Similar to 'switch', but the default value is 'True' and the active is -- 'False'.-switch' :: FlagOpt '[] Bool switch'- = fl { _fReader = boolParser }- where- fl = flag True False---- | Similar to 'switch'', but accepts a modifier function and returns an 'Opt'--- directly.-switchWith' :: (FlagOpt '[] Bool -> FlagOpt attr Bool) -> Opt Bool-switchWith' f- = toOpt $ f switch'+switch' f+ = fl { _optReader = boolParser }+ where+ fl+ = flag True False f -- | Create an argument parser, equivalent to 'Options.Applicative.argument'.--- The result can then be used with 'toOpt' to convert into the global 'Opt'--- type.------ @--- someArgument :: Opt String--- someArgument--- = toOpt ( argument strParser--- & optHelp "Some argument"--- & optDefault "this is the default"--- )--- @-argument- :: OptReader a- -> ArgumentOpt '[] a-argument p- = ArgumentOpt- { _aHelp = Nothing- , _aMetavar = Nothing- , _aEnvVar = Nothing- , _aDefault = Nothing- , _aDefaultStr = Nothing- , _aReader = p- }---- | Similar to 'argument', but accepts a modifier function and returns an--- 'Opt' directly.+-- The second argument is the modifiers to add to the option, and can be+-- defined by using function composition ('.'). -- -- @ -- someArgument :: Opt Int -- someArgument--- = argumentWith--- ( optHelp "Some argument"--- . optDefault "this is the default"+-- = argument+-- ( help "Some argument"+-- . defaultVal "this is the default" -- ) -- @-argumentWith+argument :: OptReader a -> (ArgumentOpt '[] a -> ArgumentOpt attr b) -> Opt b-argumentWith p f- = toOpt $ f (argument p)+argument p f+ = toOpt $ f opt+ where+ opt+ = ArgumentOpt+ { _aHelp = Nothing+ , _aMetavar = Nothing+ , _aEnvVar = Nothing+ , _aDefaultVal = Nothing+ , _aDefaultStr = Nothing+ , _aReader = p+ } -- | Convert a parser that returns 'Maybe' to a parser that returns 'Either', -- with the default 'Left' value @unable to parse: \<input\>@.
src/Options/Harg/Sources/JSON.hs view
@@ -20,7 +20,7 @@ deriving (Generic, B.FunctorB, B.TraversableB, B.ProductB) -- | The result of reading a JSON file. @JSONSourceNotRequired@ is used when--- the user has specified @optDefault NoConfigFile@. It holds the contents of+-- the user has specified @defaultVal NoConfigFile@. It holds the contents of -- the JSON file as a 'JSON.Value'. data JSONSourceVal = JSONSourceVal JSON.Value
src/Options/Harg/Sources/Types.hs view
@@ -71,8 +71,8 @@ -- where -- jsonOpt -- = optionWith strParser--- ( optLong "json-config"--- . optDefault (ConfigFile "~/config.json")+-- ( long "json-config"+-- . defaultVal (ConfigFile "~/config.json") -- ) -- @ --@@ -84,8 +84,8 @@ -- where -- jsonOpt -- = optionWith strParser--- ( optLong "json-config"--- . optDefault NoConfigFile+-- ( long "json-config"+-- . defaultVal NoConfigFile -- ) -- @ --
src/Options/Harg/Sources/YAML.hs view
@@ -23,7 +23,7 @@ deriving (Generic, B.FunctorB, B.TraversableB, B.ProductB) -- | The result of reading a YAML file. @YAMLSourceNotRequired@ is used when--- the user has specified @optDefault NoConfigFile@. It holds the contents of+-- the user has specified @defaultVal NoConfigFile@. It holds the contents of -- the YAML file as a 'BS.ByteString'. data YAMLSourceVal = YAMLSourceVal BS.ByteString
src/Options/Harg/Types.hs view
@@ -14,7 +14,7 @@ -- with @--help/-h@ or in case of error , _optMetavar :: Maybe String -- ^ Metavar to be shown in the help description , _optEnvVar :: Maybe String -- ^ Environment variable for use with 'EnvSource'- , _optDefault :: Maybe a -- ^ Default value+ , _optDefaultVal :: Maybe a -- ^ Default value , _optDefaultStr :: Maybe String -- ^ Default value as string (unparsed) , _optReader :: OptReader a -- ^ Option parser , _optType :: OptType a -- ^ Option type@@ -42,7 +42,7 @@ , _oHelp :: Maybe String , _oMetavar :: Maybe String , _oEnvVar :: Maybe String- , _oDefault :: Maybe a+ , _oDefaultVal :: Maybe a , _oDefaultStr :: Maybe String , _oReader :: OptReader a }@@ -51,13 +51,13 @@ -- value. Corresponds to 'Options.Applicative.flag'. data FlagOpt (attr :: [OptAttr]) a = FlagOpt- { _fLong :: Maybe String- , _fShort :: Maybe Char- , _fHelp :: Maybe String- , _fEnvVar :: Maybe String- , _fDefault :: a- , _fReader :: OptReader a- , _fActive :: a+ { _fLong :: Maybe String+ , _fShort :: Maybe Char+ , _fHelp :: Maybe String+ , _fEnvVar :: Maybe String+ , _fDefaultVal :: a+ , _fReader :: OptReader a+ , _fActive :: a } -- | Option for arguments (no long/short specifiers). Corresponds to@@ -67,7 +67,7 @@ { _aHelp :: Maybe String , _aMetavar :: Maybe String , _aEnvVar :: Maybe String- , _aDefault :: Maybe a+ , _aDefaultVal :: Maybe a , _aDefaultStr :: Maybe String , _aReader :: OptReader a }
src/Options/Harg/Util.hs view
@@ -45,8 +45,10 @@ = Compose $ Const <$> opt- { _optDefault = Just mempty- , _optReader = pure . const mempty+ { _optDefaultVal+ = Just mempty+ , _optReader+ = pure . const mempty , _optType = case _optType opt of OptionOptType -> OptionOptType