postgresql-simple-opts 0.1.0.4 → 0.1.0.5
raw patch · 2 files changed
+10/−9 lines, 2 filesdep ~optparse-applicative
Dependency ranges changed: optparse-applicative
Files
postgresql-simple-opts.cabal view
@@ -1,5 +1,5 @@ name: postgresql-simple-opts-version: 0.1.0.4+version: 0.1.0.5 synopsis: An optparse-applicative parser for postgresql-simple's connection options description: This package exports a optparse-applicative parser and type for postgresql-simple's ConnectInfo and connection string. homepage: https://github.com/jfischoff/postgresql-simple-opts#readme@@ -18,7 +18,7 @@ exposed-modules: Database.PostgreSQL.Simple.Options build-depends: base >= 4.6 && < 5 , postgresql-simple- , optparse-applicative >=0.11.0 && <0.13+ , optparse-applicative >=0.11.0 && <0.14 , bytestring , optparse-generic >= 1.0.1 && <1.2 , markdown-unlit >= 0.4.0 && <0.5
src/Database/PostgreSQL/Simple/Options.lhs view
@@ -1,8 +1,11 @@+[](https://hackage.haskell.org/package/postgresql-simple-opts)+[](http://travis-ci.org/jfischoff/postgresql-simple-opts)+ ### Composable Command Line Parsing with `optparse-applicative` There are many solutions for parsing command line arguments in Haskell. Personally I like [`optparse-applicative`](https://hackage.haskell.org/package/optparse-applicative-0.12.1.0/), because, like the title suggests, you can compose parsers out of smaller pieces. -I have written command line parsers for the database connection info for [`postgresql-simple`](https://hackage.haskell.org/package/postgresql-simple-0.5.2.1/) many times and faced with the prospect of doing it again I opted to make this library, which is also this literate Haskell file. This way I could reuse it in web servers, db migrators, db job runners ... those are all the examples I could think of ... just trust me, it's worth it.+I have written command line parsers for [`postgresql-simple's`](https://hackage.haskell.org/package/postgresql-simple-0.5.2.1/) database connection info many times. Faced with the prospect of doing it again I opted to make this library, which is also a single literate Haskell file. This way I could reuse it in web servers, db migrators, db job runners ... those are all the examples I could think of ... just trust me, it's worth it. ### Outline - [The "Partial" Option Types](#partial)@@ -17,8 +20,8 @@ ```haskell {-| A resuable optparse-applicative parser for creating a postgresql-simple- 'Connection' -|-}+ 'Connection'+-} {-# LANGUAGE RecordWildCards, LambdaCase, DeriveGeneric, DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving, CPP #-} module Database.PostgreSQL.Simple.Options where@@ -31,9 +34,7 @@ import Options.Generic import Data.Typeable import Data.String-#if !MIN_VERSION_base(4,8,0) import Data.Monoid-#endif ``` ### <a name="partial"> The "Partial" Option Types@@ -52,7 +53,7 @@ } deriving (Show, Eq, Read, Ord, Generic, Typeable) ``` -We will utilize a boilerplate prevention library by Gaberiel Gonzales called [`optparse-generic`](https://hackage.haskell.org/package/optparse-generic-1.1.3) to generate the parser for use from the records field names.+We will utilize a boilerplate prevention library by Gabriel Gonzalez called [`optparse-generic`](https://hackage.haskell.org/package/optparse-generic-1.1.3) which generates a parser from the record field names. To create the parser we have to merely declare an instance of `ParseRecord`. @@ -82,7 +83,6 @@ newtype ConnectString = ConnectString { connectString :: ByteString } deriving ( Show, Eq, Read, Ord, Generic, Typeable, IsString )- ``` I don't like the default option parsing for `String` in `optparse-applicative`. I want something that will escape double quotes, remove single quotes or just use the string unaltered. The function `parseString` does this.@@ -156,6 +156,7 @@ mkLast :: a -> Last a mkLast = Last . Just +-- | The 'PartialConnectInfo' version of 'defaultConnectInfo' defaultPartialConnectInfo :: PartialConnectInfo defaultPartialConnectInfo = PartialConnectInfo { host = mkLast $ connectHost defaultConnectInfo