dhall-toml 1.0.1 → 1.0.2
raw patch · 4 files changed
+82/−18 lines, 4 filesdep +optparse-applicativedep ~dhallPVP ok
version bump matches the API change (PVP)
Dependencies added: optparse-applicative
Dependency ranges changed: dhall
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- dhall-toml.cabal +7/−4
- src/Dhall/DhallToToml.hs +32/−5
- src/Dhall/TomlToDhall.hs +37/−9
CHANGELOG.md view
@@ -1,3 +1,9 @@+1.0.2++* [Improve command-line interface](https://github.com/dhall-lang/dhall-haskell/pull/2355)+* [Build against `optparse-applicative-0.17`](https://github.com/dhall-lang/dhall-haskell/pull/2355)+* [Build against `text-2.0`](https://github.com/dhall-lang/dhall-haskell/pull/2356)+ 1.0.1 * [Fix doctest](https://github.com/dhall-lang/dhall-haskell/pull/2325)
dhall-toml.cabal view
@@ -1,5 +1,5 @@ Name: dhall-toml-Version: 1.0.1+Version: 1.0.2 Cabal-Version: >=1.10 Build-Type: Simple License: BSD3@@ -35,16 +35,19 @@ Hs-Source-Dirs: src Build-Depends: base >= 4.12 && < 5 ,- dhall >= 1.39.0 && < 1.41 ,+ dhall >= 1.39.0 && < 1.42 , tomland >= 1.3.2.0 && < 1.4 ,- text >= 0.11.1.0 && < 1.3 ,+ text >= 0.11.1.0 && < 2.1 , containers >= 0.5.9 && < 0.7 , unordered-containers >= 0.2 && < 0.3 ,- prettyprinter >= 1.7.0 && < 1.8+ prettyprinter >= 1.7.0 && < 1.8 ,+ optparse-applicative >= 0.14 && < 0.18 Exposed-Modules: Dhall.DhallToToml Dhall.TomlToDhall Dhall.Toml.Utils+ Other-Modules:+ Paths_dhall_toml GHC-Options: -Wall Default-Language: Haskell2010
src/Dhall/DhallToToml.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE RecordWildCards #-} {-| This module exports the `dhallToToml` function for translating a Dhall syntax tree to a TOML syntax tree (`TOML`) for the @tomland@@@ -106,9 +108,10 @@ import Data.Foldable (toList) import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Text (Text)+import Data.Version (showVersion) import Data.Void (Void) import Dhall.Core (DhallDouble (..), Expr)-import Dhall.Toml.Utils (inputToDhall)+import Dhall.Toml.Utils (fileToDhall, inputToDhall) import Prettyprinter (Pretty) import Toml.Type.Key (Key (Key, unKey), Piece (Piece)) import Toml.Type.Printer (pretty)@@ -122,6 +125,8 @@ import qualified Dhall.Map as Map import qualified Dhall.Pretty import qualified Dhall.Util+import qualified Options.Applicative as OA+import qualified Paths_dhall_toml as Meta import qualified Prettyprinter.Render.Text as Pretty import qualified Toml.Type.AnyValue as Toml.AnyValue import qualified Toml.Type.TOML as Toml.TOML@@ -356,15 +361,37 @@ Core.RecordLit _ -> Left $ UnsupportedArray e _ -> Left $ Unsupported e +data Options = Options+ { input :: Maybe FilePath+ , output :: Maybe FilePath+ } +parserInfo :: OA.ParserInfo Options+parserInfo = OA.info+ (OA.helper <*> versionOption <*> optionsParser)+ (OA.fullDesc <> OA.progDesc "Convert Dhall to TOML")+ where+ versionOption = OA.infoOption (showVersion Meta.version) $+ OA.long "version" <> OA.help "Display version"+ optionsParser = do+ input <- OA.optional . OA.strOption $+ OA.long "file"+ <> OA.help "Read Dhall from file instead of standard input"+ <> fileOpts+ output <- OA.optional . OA.strOption $+ OA.long "output"+ <> OA.help "Write TOML to a file instead of standard output"+ <> fileOpts+ pure Options {..}+ fileOpts = OA.metavar "FILE" <> OA.action "file"+ {-| Runs the @dhall-to-toml@ command -} dhallToTomlMain :: IO () dhallToTomlMain = do- resolvedExpression <- inputToDhall+ Options {..} <- OA.execParser parserInfo+ resolvedExpression <- maybe inputToDhall fileToDhall input toml <- case dhallToToml resolvedExpression of Left err -> throwIO err Right toml -> return toml- Text.IO.putStrLn $ pretty toml--+ maybe Text.IO.putStrLn Text.IO.writeFile output $ pretty toml
src/Dhall/TomlToDhall.hs view
@@ -1,5 +1,7 @@+{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedLists #-}+{-# LANGUAGE RecordWildCards #-} {-| This module exports the `tomlToDhall` function for translating a TOML syntax tree from @tomland@ to a Dhall syntax tree. For now,@@ -121,6 +123,7 @@ import Data.Foldable (foldl', toList) import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Text (Text)+import Data.Version (showVersion) import Data.Void (Void) import Dhall.Core (DhallDouble (..), Expr) import Dhall.Parser (Src)@@ -138,7 +141,8 @@ import qualified Data.Text.IO as Text.IO import qualified Dhall.Core as Core import qualified Dhall.Map as Map-import qualified System.Environment+import qualified Options.Applicative as OA+import qualified Paths_dhall_toml as Meta import qualified Toml.Parser import qualified Toml.Type.AnyValue as Toml.AnyValue import qualified Toml.Type.PrefixTree as Toml.PrefixTree@@ -295,20 +299,44 @@ tables = tablesToObject $ Toml.TOML.tomlTables toml tableArrays = tableArraysToObject $ Toml.TOML.tomlTableArrays toml +data Options = Options+ { input :: Maybe FilePath+ , output :: Maybe FilePath+ , schemaFile :: FilePath+ }++parserInfo :: OA.ParserInfo Options+parserInfo = OA.info+ (OA.helper <*> versionOption <*> optionsParser)+ (OA.fullDesc <> OA.progDesc "Convert TOML to Dhall")+ where+ versionOption = OA.infoOption (showVersion Meta.version) $+ OA.long "version" <> OA.help "Display version"+ optionsParser = do+ input <- OA.optional . OA.strOption $+ OA.long "file"+ <> OA.help "Read TOML from file instead of standard input"+ <> fileOpts+ output <- OA.optional . OA.strOption $+ OA.long "output"+ <> OA.help "Write Dhall to a file instead of standard output"+ <> fileOpts+ schemaFile <- OA.strArgument $+ OA.help "Path to Dhall schema file"+ <> OA.action "file"+ <> OA.metavar "SCHEMA"+ pure Options {..}+ fileOpts = OA.metavar "FILE" <> OA.action "file"+ tomlToDhallMain :: IO () tomlToDhallMain = do- text <- Text.IO.getContents+ Options {..} <- OA.execParser parserInfo+ text <- maybe Text.IO.getContents Text.IO.readFile input toml <- case Toml.Parser.parse text of Left tomlErr -> throwIO (InvalidToml tomlErr) Right toml -> return toml- args <- System.Environment.getArgs- schemaFile <- case args of- [] -> fail "schema not provided"- schemaFile:[] -> return schemaFile- _ -> fail "too many agrgs" schema <- fileToDhall schemaFile dhall <- case tomlToDhall schema toml of Left err -> throwIO err Right dhall -> return dhall- Text.IO.putStrLn $ Core.pretty dhall-+ maybe Text.IO.putStrLn Text.IO.writeFile output $ Core.pretty dhall