Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --quiet option for dhall decode #1803

Merged
merged 2 commits into from
May 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions dhall/src/Dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ data Mode
, followSymlinks :: Bool
}
| Encode { file :: Input, json :: Bool }
| Decode { file :: Input, json :: Bool }
| Decode { file :: Input, json :: Bool, quiet :: Bool }
| Text { file :: Input }
| DirectoryTree { file :: Input, path :: FilePath }
| SyntaxTree { file :: Input }
Expand Down Expand Up @@ -263,7 +263,7 @@ parseMode =
Convert
"decode"
"Decode a Dhall expression from binary"
(Decode <$> parseFile <*> parseJSONFlag)
(Decode <$> parseFile <*> parseJSONFlag <*> parseQuiet)
<|> subcommand
Miscellaneous
"repl"
Expand Down Expand Up @@ -380,7 +380,7 @@ parseMode =
parseQuiet =
Options.Applicative.switch
( Options.Applicative.long "quiet"
<> Options.Applicative.help "Don't print the inferred type"
<> Options.Applicative.help "Don't print the result"
)

parseInplace = fmap f (optional p)
Expand Down Expand Up @@ -822,9 +822,15 @@ command (Options {..}) = do
Dhall.Core.throws (Dhall.Binary.decodeExpression bytes)


let doc = Dhall.Pretty.prettyCharacterSet characterSet (Dhall.Core.renote expression :: Expr Src Import)
if quiet
then return ()
else do
let doc =
Dhall.Pretty.prettyCharacterSet
characterSet
(Dhall.Core.renote expression :: Expr Src Import)
Comment on lines +825 to +831
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(style comment) use unless (from Control.Monad):

Suggested change
if quiet
then return ()
else do
let doc =
Dhall.Pretty.prettyCharacterSet
characterSet
(Dhall.Core.renote expression :: Expr Src Import)
unless quiet $ do
let doc =
Dhall.Pretty.prettyCharacterSet
characterSet
(Dhall.Core.renote expression :: Expr Src Import)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. When I started contributing to dhall, I often wanted to use unless and similar utils too, but realized that Gabriel mostly sticks to if. These days, I find this if-style actually more readable than the implicit negation of unless.


renderDoc System.IO.stdout doc
renderDoc System.IO.stdout doc

Text {..} -> do
expression <- getExpression file
Expand Down