optima 0.2 → 0.3
raw patch · 3 files changed
+29/−30 lines, 3 files
Files
- demo/Main.hs +21/−12
- library/Optima.hs +7/−17
- optima.cabal +1/−1
demo/Main.hs view
@@ -15,15 +15,24 @@ (Optima.showable True) Optima.unformatted (Optima.explicitlyParsed Attoparsec.bool)))- (Optima.param (Just 'b') "arg-b"- (Optima.value- "Description of B"- Optima.defaultless- Optima.unformatted- (Optima.explicitlyParsed Attoparsec.text)))- (Optima.param Nothing "arg-c"- (Optima.value- ""- Optima.defaultless- Optima.unformatted- (Optima.explicitlyParsed Attoparsec.utf8Bytes))))+ (Optima.group "group1"+ (liftA2 (,)+ (Optima.member "bb"+ (Optima.value+ "Description of B"+ Optima.defaultless+ Optima.unformatted+ (Optima.explicitlyParsed Attoparsec.text)))+ (Optima.member "d" textParam)))+ (Optima.group "group-of-alternatives"+ (asum [+ Optima.member "e" textParam,+ Optima.subgroup "subgroup" (asum [+ Optima.member "f" textParam,+ Optima.member "g" (flag $> "slkdfjsdkj")+ ])+ ])))+ where+ textParam = Optima.value "Text param" Optima.defaultless Optima.unformatted (Optima.explicitlyParsed Attoparsec.text)+ flag = Optima.flag "Flag type 1"+ bytesParam = Optima.value "" Optima.defaultless Optima.unformatted (Optima.explicitlyParsed Attoparsec.utf8Bytes)
library/Optima.hs view
@@ -5,16 +5,15 @@ -- * Params Params, param,- paramGroup,+ group, -- * ParamGroup ParamGroup, member,- memberGroup,+ subgroup, -- * Param Param, value, flag,- switch, -- * Value Value, explicitlyParsed,@@ -32,7 +31,7 @@ ) where -import Optima.Prelude+import Optima.Prelude hiding (group) import qualified Data.Text as Text import qualified Data.Attoparsec.Text as Attoparsec import qualified Options.Applicative as Optparse@@ -140,8 +139,8 @@ The param group cannot use short names, only long names. -}-paramGroup :: Text {-^ Prefix for the long names of the parameters. If empty, then there'll be no prefixing -} -> ParamGroup a -> Params a-paramGroup prefix (ParamGroup parser) = Params (parser prefix)+group :: Text {-^ Prefix for the long names of the parameters. If empty, then there'll be no prefixing -} -> ParamGroup a -> Params a+group prefix (ParamGroup parser) = Params (parser prefix) -- ** ParamGroup@@ -156,8 +155,8 @@ {-| Unite a group by a shared prefix. -}-memberGroup :: Text {-^ Long name prefix -} -> ParamGroup a -> ParamGroup a-memberGroup prefix (ParamGroup parser) = ParamGroup (\ higherPrefix -> parser (prefixIfMakesSense higherPrefix prefix))+subgroup :: Text {-^ Long name prefix -} -> ParamGroup a -> ParamGroup a+subgroup prefix (ParamGroup parser) = ParamGroup (\ higherPrefix -> parser (prefixIfMakesSense higherPrefix prefix)) -- ** Param@@ -185,15 +184,6 @@ flag description = Param (\ shortName longName -> Optparse.flag' ()- (longParamName longName <> foldMap Optparse.short shortName <> paramHelp description UnspecifiedFormat))--{-|-A parameter with no value, the presence of which is interpreted as 'True'.--}-switch :: Text {-^ Description. Can be empty -} -> Param Bool-switch description =- Param (\ shortName longName ->- Optparse.switch (longParamName longName <> foldMap Optparse.short shortName <> paramHelp description UnspecifiedFormat))
optima.cabal view
@@ -1,5 +1,5 @@ name: optima-version: 0.2+version: 0.3 category: CLI, Parsing, Options synopsis: Simple command line interface arguments parser homepage: https://github.com/metrix-ai/optima