summaryrefslogtreecommitdiff
path: root/dhall-to-yaml/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dhall-to-yaml/Main.hs')
-rw-r--r--dhall-to-yaml/Main.hs28
1 files changed, 10 insertions, 18 deletions
diff --git a/dhall-to-yaml/Main.hs b/dhall-to-yaml/Main.hs
index cec56be..fd516df 100644
--- a/dhall-to-yaml/Main.hs
+++ b/dhall-to-yaml/Main.hs
@@ -1,10 +1,10 @@
-{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
import Control.Exception (SomeException)
+import Data.Aeson (Value)
import Data.Monoid ((<>))
import Dhall.JSON (Conversion)
import Options.Applicative (Parser, ParserInfo)
@@ -23,18 +23,18 @@ import qualified System.IO
data Options = Options
{ explain :: Bool
- , omitNull :: Bool
+ , omission :: Value -> Value
, documents :: Bool
, conversion :: Conversion
}
parseOptions :: Parser Options
-parseOptions = Options.Applicative.helper <*> do
- explain <- parseExplain
- omitNull <- parseOmitNull
- documents <- parseDocuments
- conversion <- Dhall.JSON.parseConversion
- return (Options {..})
+parseOptions =
+ Options
+ <$> parseExplain
+ <*> Dhall.JSON.parseOmission
+ <*> parseDocuments
+ <*> Dhall.JSON.parseConversion
where
parseExplain =
Options.Applicative.switch
@@ -42,12 +42,6 @@ parseOptions = Options.Applicative.helper <*> do
<> Options.Applicative.help "Explain error messages in detail"
)
- parseOmitNull =
- Options.Applicative.switch
- ( Options.Applicative.long "omitNull"
- <> Options.Applicative.help "Omit record fields that are null"
- )
-
parseDocuments =
Options.Applicative.switch
( Options.Applicative.long "documents"
@@ -57,7 +51,7 @@ parseOptions = Options.Applicative.helper <*> do
parserInfo :: ParserInfo Options
parserInfo =
Options.Applicative.info
- parseOptions
+ (Options.Applicative.helper <*> parseOptions)
( Options.Applicative.fullDesc
<> Options.Applicative.progDesc "Compile Dhall to YAML"
)
@@ -71,11 +65,9 @@ main = do
handle $ do
let explaining = if explain then Dhall.detailed else id
- let omittingNull = if omitNull then Dhall.JSON.omitNull else id
-
stdin <- Data.Text.IO.getContents
- json <- omittingNull <$> explaining (Dhall.JSON.codeToValue conversion "(stdin)" stdin)
+ json <- omission <$> explaining (Dhall.JSON.codeToValue conversion "(stdin)" stdin)
let yaml = case (documents, json) of
(True, Data.Yaml.Array elems)