@@ -99,6 +99,7 @@ import qualified Dhall.Lint
9999import qualified Dhall.Map
100100import qualified Dhall.Package
101101import qualified Dhall.Pretty
102+ import Dhall.Pretty.Internal (ChooseCharacterSet (.. ), chooseCharsetOrUseDefault )
102103import qualified Dhall.Repl
103104import qualified Dhall.Schemas
104105import qualified Dhall.Tags
@@ -122,7 +123,7 @@ data Options = Options
122123 { mode :: Mode
123124 , explain :: Bool
124125 , plain :: Bool
125- , chosenCharacterSet :: Maybe CharacterSet
126+ , chosenCharacterSet :: ChooseCharacterSet
126127 , censor :: Censor
127128 }
128129
@@ -221,16 +222,16 @@ parseOptions =
221222
222223 parseCharacterSet =
223224 Options.Applicative. flag'
224- (Just Unicode )
225+ (Specify Unicode )
225226 ( Options.Applicative. long " unicode"
226227 <> Options.Applicative. help " Format code using only Unicode syntax"
227228 )
228229 <|> Options.Applicative. flag'
229- (Just ASCII )
230+ (Specify ASCII )
230231 ( Options.Applicative. long " ascii"
231232 <> Options.Applicative. help " Format code using only ASCII syntax"
232233 )
233- <|> pure Nothing
234+ <|> pure AutoInferCharSet
234235
235236subcommand :: Group -> String -> String -> Parser a -> Parser a
236237subcommand group name description parser =
@@ -634,7 +635,7 @@ command (Options {..}) = do
634635 let getExpressionAndCharacterSet file = do
635636 expr <- getExpression file
636637
637- let characterSet = fromMaybe (detectCharacterSet expr) chosenCharacterSet
638+ let characterSet = chooseCharsetOrUseDefault (detectCharacterSet expr) chosenCharacterSet
638639
639640 return (expr, characterSet)
640641
@@ -833,7 +834,7 @@ command (Options {..}) = do
833834
834835 Repl ->
835836 Dhall.Repl. repl
836- (fromMaybe Unicode chosenCharacterSet) -- Default to Unicode if no characterSet specified
837+ (chooseCharsetOrUseDefault Unicode chosenCharacterSet) -- Default to Unicode if no characterSet specified
837838 explain
838839
839840 Diff {.. } -> do
@@ -908,7 +909,7 @@ command (Options {..}) = do
908909 (Header header, parsedExpression) <-
909910 Dhall.Util. getExpressionAndHeaderFromStdinText censor inputName originalText
910911
911- let characterSet = fromMaybe (detectCharacterSet parsedExpression) chosenCharacterSet
912+ let characterSet = chooseCharsetOrUseDefault (detectCharacterSet parsedExpression) chosenCharacterSet
912913
913914 case transitivity of
914915 Transitive ->
@@ -994,7 +995,7 @@ command (Options {..}) = do
994995 else do
995996 let doc =
996997 Dhall.Pretty. prettyCharacterSet
997- (fromMaybe Unicode chosenCharacterSet) -- default to Unicode
998+ (chooseCharsetOrUseDefault Unicode chosenCharacterSet) -- default to Unicode
998999 (Dhall.Core. renote expression :: Expr Src Import )
9991000
10001001 renderDoc System.IO. stdout doc
@@ -1060,10 +1061,16 @@ command (Options {..}) = do
10601061
10611062 Package {.. } -> do
10621063 let options = appEndo
1063- (maybe mempty (Endo . set Dhall.Package. characterSet) chosenCharacterSet
1064+ (maybe mempty (Endo . set Dhall.Package. characterSet) chosenCharacterSetAsMaybe
10641065 <> packageOptions
10651066 ) Dhall.Package. defaultOptions
10661067 writePackage options packageFiles
1068+ where
1069+ chosenCharacterSetAsMaybe :: Maybe CharacterSet
1070+ chosenCharacterSetAsMaybe = case chosenCharacterSet of
1071+ AutoInferCharSet -> Nothing
1072+ Specify c -> Just c
1073+
10671074
10681075-- | Entry point for the @dhall@ executable
10691076main :: IO ()
0 commit comments