Add --compact flag to dhall-to-json (#743)

This is phase 1 of transitioning to pretty-printing by default, as
described here:

https://github.com/dhall-lang/dhall-haskell/issues/716#issuecomment-445485153

This flag allows users who prefer the compact format a smooth migration
path
This commit is contained in:
Gabriel Gonzalez 2018-12-09 08:17:33 -08:00 committed by GitHub
parent cfe62c99e9
commit db6f80fec2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
module Main where
import Control.Applicative ((<|>))
import Control.Exception (SomeException)
import Control.Monad (when)
import Data.Monoid ((<>))
@ -49,10 +50,24 @@ parseOptions = Options.Applicative.helper <*> do
)
parsePretty =
Options.Applicative.switch
( Options.Applicative.long "pretty"
<> Options.Applicative.help "Pretty print generated JSON"
)
prettyFlag <|> compactFlag <|> defaultBehavior
where
prettyFlag =
Options.Applicative.flag'
True
( Options.Applicative.long "pretty"
<> Options.Applicative.help "Pretty print generated JSON"
)
compactFlag =
Options.Applicative.flag'
False
( Options.Applicative.long "compact"
<> Options.Applicative.help "Render JSON on one line"
)
defaultBehavior =
pure False
parseOmitNull =
Options.Applicative.switch