proto-lens-optparse 0.1.0.4 → 0.1.1.0
raw patch · 3 files changed
+76/−30 lines, 3 filesdep ~proto-lensPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: proto-lens
API changes (from Hackage documentation)
+ Data.ProtoLens.Optparse: enumArgument :: MessageEnum a => Mod ArgumentFields a -> Parser a
+ Data.ProtoLens.Optparse: enumOption :: MessageEnum a => Mod OptionFields a -> Parser a
+ Data.ProtoLens.Optparse: protoEnum :: MessageEnum a => ReadM a
Files
- Changelog.md +10/−5
- proto-lens-optparse.cabal +39/−23
- src/Data/ProtoLens/Optparse.hs +27/−2
Changelog.md view
@@ -1,20 +1,25 @@ # Changelog for `proto-lens-optparse` -## Unreleased changes+## v0.1.1.0+- Add MessageEnum ReadM and option builders (#181). +## v0.1.0.5+- Remove support for `ghc-7.10`. (#136)+- Use a `.cabal` file that's auto-generated from `hpack`. (#138)+ ## v0.1.0.4 - Bump the dependency on `base` to support `ghc-8.2.1`. -## 0.1.0.3+## v0.1.0.3 - Bump the dependency for `optparse-applicative-0.14`. -## 0.1.0.2+## v0.1.0.2 - Bump the dependencies for `optparse-applicative-0.13` and `proto-lens-0.2`. -## 0.1.0.1+## v0.1.0.1 - Bump the dependency on `base` to support `ghc-8.0`. -## 0.1.0.0+## v0.1.0.0 Initial version.
proto-lens-optparse.cabal view
@@ -1,26 +1,42 @@-name: proto-lens-optparse-version: 0.1.0.4-synopsis: Adapting proto-lens to optparse-applicative ReadMs.-description:- A package adapting proto-lens to optparse-applicative ReadMs.- This gives an easy way to define options and arguments for- text-format protobuf types.+-- This file has been generated from package.yaml by hpack version 0.20.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: fb04dc4a9f5b32b3fafbac2528f61972244ef20a009528c1b872a9542ac3165d -homepage: https://github.com/google/proto-lens-license: BSD3-license-file: LICENSE-author: Andrew Pritchard-maintainer: awpr+protolens@google.com-copyright: Google Inc.-category: Data-build-type: Simple-cabal-version: >=1.8-extra-source-files: Changelog.md+name: proto-lens-optparse+version: 0.1.1.0+synopsis: Adapting proto-lens to optparse-applicative ReadMs.+description: A package adapting proto-lens to optparse-applicative ReadMs. This gives an easy way to define options and arguments for text-format protobuf types.+category: Data+homepage: https://github.com/google/proto-lens#readme+bug-reports: https://github.com/google/proto-lens/issues+author: Andrew Pritchard+maintainer: awpr+protolens@google.com+copyright: Google Inc.+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10 +extra-source-files:+ Changelog.md++source-repository head+ type: git+ location: https://github.com/google/proto-lens+ subdir: proto-lens-optparse+ library- hs-source-dirs: src- exposed-modules: Data.ProtoLens.Optparse- build-depends: proto-lens >= 0.1 && < 0.3- , base >= 4.8 && < 4.11- , optparse-applicative >= 0.12 && < 0.15- , text == 1.2.*+ hs-source-dirs:+ src+ build-depends:+ base >=4.8 && <4.11+ , optparse-applicative >=0.12 && <0.15+ , proto-lens >=0.1 && <0.4+ , text ==1.2.*+ exposed-modules:+ Data.ProtoLens.Optparse+ other-modules:+ Paths_proto_lens_optparse+ default-language: Haskell2010
src/Data/ProtoLens/Optparse.hs view
@@ -8,12 +8,19 @@ -- This gives an easy way to define options and arguments for -- text-format protobuf types. module Data.ProtoLens.Optparse- ( proto+ ( -- * Messages+ proto , protoOption , protoArgument+ -- * Enums+ , protoEnum+ , enumOption+ , enumArgument ) where -import Data.ProtoLens.Message (Message)+import Control.Applicative ((<|>))+import Control.Monad ((<=<))+import Data.ProtoLens.Message (Message, MessageEnum(readEnum, maybeToEnum)) import Data.ProtoLens.TextFormat (readMessage) import qualified Data.Text.Lazy as TL import Options.Applicative@@ -26,6 +33,7 @@ , eitherReader , option )+import Text.Read (readMaybe) -- | An optparse-applicative 'ReadM' for a text-format protobuf. This lets you -- have flags or arguments with protobuf values.@@ -39,3 +47,20 @@ -- | Shorthand for a text-format protobuf argument. protoArgument :: Message a => Mod ArgumentFields a -> Parser a protoArgument = argument proto++-- We define our own maybeReader to preserve compatibility with versions of+-- optparse-applicative that don't provide it (< 0.13.0.0).+maybeReader :: (String -> Maybe a) -> ReadM a+maybeReader = eitherReader . fmap (maybe (Left "No parse") Right)++-- | An optparse-applicative 'ReadM' for an enum name or number.+protoEnum :: MessageEnum a => ReadM a+protoEnum = maybeReader readEnum <|> maybeReader (maybeToEnum <=< readMaybe)++-- | Shorthand for a text-format enumbuf option.+enumOption :: MessageEnum a => Mod OptionFields a -> Parser a+enumOption = option protoEnum++-- | Shorthand for a text-format enumbuf argument.+enumArgument :: MessageEnum a => Mod ArgumentFields a -> Parser a+enumArgument = argument protoEnum