packages feed

optparse-generic 1.2.3 → 1.3.0

raw patch · 3 files changed

+38/−45 lines, 3 filesdep ~optparse-applicativedep ~semigroupsdep ~time

Dependency ranges changed: optparse-applicative, semigroups, time

Files

+ CHANGELOG.md view
@@ -0,0 +1,11 @@+1.3.0++* BREAKING CHANGE: New `metavar` method for `ParseField` class+    * This field simplifies customizing `ParseField` instances+        * Now you usually only need to override `metavar` now or possibly also+          `readField`, whereas the default behavior for `parseField` should work+          more often+    * This is only a breaking change for data types that use the default+      implementation of `ParseField` but do not derive `Typeable`+    * You can migrate existing code that doesn't compile by just explicitly+      specifying what the `metavar` field should be
optparse-generic.cabal view
@@ -1,5 +1,5 @@ Name: optparse-generic-Version: 1.2.3+Version: 1.3.0 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -16,6 +16,7 @@     See the documentation in "Options.Generic" for an example of how to use     this library Category: System+Extra-Source-Files: CHANGELOG.md Source-Repository head     Type: git     Location: https://github.com/Gabriel439/Haskell-Optparse-Generic-Library
src/Options/Generic.hs view
@@ -365,8 +365,7 @@         -- ^ Short name         -> Parser a     default parseField-        :: (Typeable a, Read a)-        => Maybe Text+        :: Maybe Text         -- ^ Help message         -> Maybe Text         -- ^ Field label@@ -374,14 +373,14 @@         -- ^ Short name         -> Parser a     parseField h m c = do-        let metavar = map toUpper (show (Data.Typeable.typeOf (undefined :: a)))+        let proxy = Proxy :: Proxy a         case m of             Nothing   -> do-                let fs =  Options.metavar metavar+                let fs =  Options.metavar (metavar proxy)                        <> foldMap (Options.help . Data.Text.unpack) h                 Options.argument readField fs             Just name -> do-                let fs =  Options.metavar metavar+                let fs =  Options.metavar (metavar proxy)                        <> Options.long (Data.Text.unpack name)                        <> foldMap (Options.help . Data.Text.unpack) h                        <> foldMap Options.short c@@ -405,6 +404,10 @@     default readField :: Read a => ReadM a     readField = auto +    metavar :: proxy a -> String+    default metavar :: Typeable a => proxy a -> String+    metavar _ = map toUpper (show (Data.Typeable.typeOf (undefined :: a)))+ instance ParseField Bool instance ParseField Double instance ParseField Float@@ -450,30 +453,20 @@     parseField = parseHelpfulString "STRING"  instance ParseField Char where-    parseField h m c = do-        let metavar = "CHAR"-        let readM = do-                s <- Options.readerAsk-                case s of-                    [ch] -> return ch-                    _    -> Options.readerAbort Options.ShowHelpText-        case m of-            Nothing   -> do-                let fs =  Options.metavar metavar-                       <> foldMap (Options.help . Data.Text.unpack) h-                Options.argument readM fs-            Just name -> do-                let fs =  Options.metavar metavar-                       <> Options.long (Data.Text.unpack name)-                       <> foldMap (Options.help . Data.Text.unpack) h-                       <> foldMap Options.short c-                Options.option   readM fs+    metavar _ = "CHAR"+    readField = do+        s <- Options.readerAsk+        case s of+            [ch] -> return ch+            _    -> Options.readerAbort Options.ShowHelpText      parseListOfField = parseHelpfulString "STRING"  instance ParseField Any where+    metavar _ = "ANY"     parseField h m c = Any <$> parseField h m c instance ParseField All where+    metavar _ = "ALL"     parseField h m c = All <$> parseField h m c  parseHelpfulString@@ -508,28 +501,15 @@     readField = Options.str  instance ParseField Data.Time.Calendar.Day where-    parseField h m c = do-        let metavar = "YYYY-MM-DD"-        case m of-            Nothing   -> do-                let fs =  Options.metavar metavar-                       <> foldMap (Options.help . Data.Text.unpack) h-                Options.argument iso8601Day fs-            Just name -> do-                let fs =  Options.metavar metavar-                       <> Options.long (Data.Text.unpack name)-                       <> foldMap (Options.help . Data.Text.unpack) h-                       <> foldMap Options.short c-                Options.option   iso8601Day fs+    metavar _ = "YYYY-MM-DD"+    readField = Options.eitherReader+              $ runReadS . Data.Time.Format.readSTime+                            False+                            Data.Time.Format.defaultTimeLocale+                            "%F"         where-        iso8601Day = Options.eitherReader-                   $ runReadS . Data.Time.Format.readSTime-                                  False-                                  Data.Time.Format.defaultTimeLocale-                                  "%F"--        runReadS [(day, "")] = Right day-        runReadS _           = Left "expected YYYY-MM-DD"+            runReadS [(day, "")] = Right day+            runReadS _           = Left "expected YYYY-MM-DD"  {-| A class for all types that can be parsed from zero or more arguments/options     on the command line@@ -633,6 +613,7 @@     parseField _ m c = Helpful <$>       parseField ((Just . Data.Text.pack .symbolVal) (Proxy :: Proxy h)) m c     readField = Helpful <$> readField+    metavar _ = metavar (Proxy :: Proxy a)  instance (ParseFields a, KnownSymbol h) => ParseFields (a <?> h) where     parseFields _ m c = Helpful <$>