optparse-applicative-simple (empty) → 1
raw patch · 7 files changed
+225/−0 lines, 7 filesdep +attoparsecdep +attoparsec-datadep +base-preludesetup-changed
Dependencies added: attoparsec, attoparsec-data, base-prelude, optparse-applicative, optparse-applicative-simple, rerebase, text
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- demo/Main.hs +20/−0
- library/OptparseApplicative/Simple/IO.hs +26/−0
- library/OptparseApplicative/Simple/Parser.hs +43/−0
- library/OptparseApplicative/Simple/ParserInfo.hs +28/−0
- optparse-applicative-simple.cabal +84/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2017, Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ demo/Main.hs view
@@ -0,0 +1,20 @@+module Main where++import Prelude+import qualified OptparseApplicative.Simple.Parser as A+import qualified OptparseApplicative.Simple.IO as B+import qualified Attoparsec.Data.Explicit as B+++main =+ B.parser "demo" parser >>= print+ where+ parser =+ (,,) <$> arg1 <*> arg2 <*> arg3+ where+ arg1 =+ A.argument "arg1" (Just 'a') (Just "Description1") (Just (True, "True")) B.bool+ arg2 =+ A.argument "arg2" Nothing Nothing Nothing B.text+ arg3 =+ A.argument "arg3" Nothing Nothing Nothing B.utf8Bytes <|> pure ""
+ library/OptparseApplicative/Simple/IO.hs view
@@ -0,0 +1,26 @@+module OptparseApplicative.Simple.IO+(+ parser,+)+where++import BasePrelude+import Data.Text (Text)+import qualified OptparseApplicative.Simple.Parser as D+import qualified OptparseApplicative.Simple.ParserInfo as C+import qualified Options.Applicative as B+++{-|+Parses the application arguments and outputs help when needed.+-}+parser + :: Text -- ^ Program description+ -> D.Parser a -- ^ Arguments specification+ -> IO a -- ^ IO action producing the parsed arguments+parser description parser =+ parserInfo (C.parser description parser)++parserInfo :: C.ParserInfo a -> IO a+parserInfo =+ B.execParser
+ library/OptparseApplicative/Simple/Parser.hs view
@@ -0,0 +1,43 @@+module OptparseApplicative.Simple.Parser+(+ Parser,+ argument,+)+where++import BasePrelude+import Data.Text (Text)+import qualified Options.Applicative as A+import qualified Data.Attoparsec.Text as B+import qualified Data.Text as C+++{-|+Specification of a command line arguments parser and help generator.++Has instances of 'Functor', 'Applicative' and 'Alternative',+which you can use for composition.+-}+type Parser =+ A.Parser++{-|+Definition of a single argument.+-}+argument+ :: Text -- ^ Long name+ -> Maybe Char -- ^ Possible short name+ -> Maybe Text -- ^ Possible description+ -> Maybe (a, Text) -- ^ Possible default value with its text representation to display in the generated help+ -> B.Parser a -- ^ Attoparsec parser of the value. The \"attoparsec-data\" package provides such parsers for a lot of standard types+ -> A.Parser a+argument longName shortName description defaultValue parser =+ A.option readM mods+ where+ readM =+ A.eitherReader (B.parseOnly parser . C.pack)+ mods =+ A.long (C.unpack longName) <>+ foldMap A.short shortName <>+ foldMap (A.help . C.unpack) description <>+ foldMap (\(value, text) -> A.value value <> A.showDefaultWith (const (C.unpack text))) defaultValue
+ library/OptparseApplicative/Simple/ParserInfo.hs view
@@ -0,0 +1,28 @@+module OptparseApplicative.Simple.ParserInfo+(+ parser,+ -- * Reexports+ B.ParserInfo,+)+where++import BasePrelude+import Data.Text (Text)+import qualified OptparseApplicative.Simple.Parser as C+import qualified Options.Applicative as B+import qualified Data.Text as D+++{-|+Constructs ParserInfo from Parser.+-}+parser + :: Text -- ^ Program description+ -> B.Parser a -- ^ Parser+ -> B.ParserInfo a+parser description parser =+ B.info (B.helper <*> parser) mods+ where+ mods =+ B.fullDesc <>+ B.progDesc (D.unpack description)
+ optparse-applicative-simple.cabal view
@@ -0,0 +1,84 @@+name:+ optparse-applicative-simple+version:+ 1+category:+ CLI, Parsing, Options+synopsis:+ Simple command line interface arguments parser+description:+ A very simple API for the \"optparse-applicative\" library,+ which maintains the compatibility with it,+ while being completely self-sufficient.+ IOW, you don't need to depend on \"optparse-applicative\" to+ apply this library,+ yet you still can integrate with it, when needed.+homepage:+ https://github.com/nikita-volkov/optparse-applicative-simple+bug-reports:+ https://github.com/nikita-volkov/optparse-applicative-simple/issues+author:+ Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+ Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+ (c) 2017, Nikita Volkov+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >= 1.10++source-repository head+ type:+ git+ location:+ git://github.com/nikita-volkov/optparse-applicative-simple.git++library+ hs-source-dirs:+ library+ exposed-modules:+ OptparseApplicative.Simple.Parser+ OptparseApplicative.Simple.IO+ other-modules:+ OptparseApplicative.Simple.ParserInfo+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ default-language:+ Haskell2010+ build-depends:+ -- + optparse-applicative == 0.13.*,+ attoparsec == 0.13.*,+ -- + text == 1.*,+ base-prelude < 2++test-suite demo+ type:+ exitcode-stdio-1.0+ hs-source-dirs:+ demo+ main-is:+ Main.hs+ ghc-options:+ -O2+ -threaded+ "-with-rtsopts=-N"+ ghc-prof-options:+ -O2+ -threaded+ -fprof-auto+ "-with-rtsopts=-N -p -s -h -i0.1"+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ default-language:+ Haskell2010+ build-depends:+ optparse-applicative-simple,+ attoparsec-data == 0.1.*,+ rerebase == 1.*