dhall-text 1.0.10 → 1.0.11
raw patch · 3 files changed
+64/−24 lines, 3 filesdep +optparse-applicativedep −optparse-genericdep ~dhall
Dependencies added: optparse-applicative
Dependencies removed: optparse-generic
Dependency ranges changed: dhall
Files
- README.md +1/−1
- dhall-text.cabal +7/−5
- exec/Main.hs +56/−18
README.md view
@@ -1,4 +1,4 @@-# `dhall-text 1.0.10`+# `dhall-text 1.0.11` This `dhall-text` package provides a `dhall-to-text` executable which you can use to template text using the Dhall configuration language.
dhall-text.cabal view
@@ -1,5 +1,5 @@ Name: dhall-text-Version: 1.0.10+Version: 1.0.11 Cabal-Version: >=1.8.0.2 Build-Type: Simple Tested-With: GHC == 7.10.2, GHC == 8.0.1@@ -24,8 +24,10 @@ Hs-Source-Dirs: exec Main-Is: Main.hs Build-Depends:- base >= 4.8.0.0 && < 5 ,- dhall >= 1.14.0 && < 1.15,- optparse-generic >= 1.1.1 && < 1.4 ,- text >= 0.11.1.0 && < 1.3+ base >= 4.8.0.0 && < 5 ,+ dhall >= 1.15.0 && < 1.16,+ optparse-applicative < 0.15,+ text >= 0.11.1.0 && < 1.3 GHC-Options: -Wall+ Other-Modules:+ Paths_dhall_text
exec/Main.hs view
@@ -1,25 +1,63 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE DeriveAnyClass #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE ExplicitNamespaces #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE RecordWildCards #-} -import Options.Generic (Generic, ParseRecord, type (<?>)(..))+import Control.Applicative ((<|>))+import Data.Monoid ((<>))+import Options.Applicative (Parser, ParserInfo) -import qualified Data.Text.Lazy.IO+import qualified Data.Text.IO+import qualified Data.Version import qualified Dhall-import qualified Options.Generic+import qualified Options.Applicative+import qualified Paths_dhall_text -newtype Options = Options- { explain :: Bool <?> "Explain error messages in detail"- } deriving (Generic, ParseRecord)+data Options+ = Default { explain :: Bool }+ | Version +parseOptions :: Parser Options+parseOptions = parseVersion <|> parseDefault+ where+ parseVersion =+ Options.Applicative.subparser+ ( Options.Applicative.command "version" parserInfoVersion+ <> Options.Applicative.metavar "version"+ )+ where+ parserInfoVersion =+ Options.Applicative.info parser+ ( Options.Applicative.fullDesc+ <> Options.Applicative.progDesc "Display version"+ )++ parser =+ Options.Applicative.helper <*> pure Version++ parseDefault = Default <$> parseExplain+ where+ parseExplain =+ Options.Applicative.switch+ ( Options.Applicative.long "explain"+ <> Options.Applicative.help "Explain error messages in detail"+ )++parserInfoOptions :: ParserInfo Options+parserInfoOptions =+ Options.Applicative.info+ (Options.Applicative.helper <*> parseOptions)+ ( Options.Applicative.progDesc "Template text using Dhall"+ <> Options.Applicative.fullDesc+ )+ main :: IO () main = do- Options {..} <- Options.Generic.getRecord "Template text using Dhall"- let detail = if unHelpful explain then Dhall.detailed else id- code <- Data.Text.Lazy.IO.getContents- text <- detail (Dhall.input Dhall.auto code)- Data.Text.Lazy.IO.putStr text+ options <- Options.Applicative.execParser parserInfoOptions++ case options of+ Default {..} -> do+ let detail = if explain then Dhall.detailed else id+ code <- Data.Text.IO.getContents+ text <- detail (Dhall.input Dhall.auto code)+ Data.Text.IO.putStr text++ Version -> do+ putStrLn (Data.Version.showVersion Paths_dhall_text.version)