@@ -22,17 +22,11 @@ main :: IO ()
2222main = withPrettyOrmoluExceptions $ do
2323 Opts {..} <- execParser optsParserInfo
2424 config <- case optConfigFile of
25− Nothing -> return Config
26− { cfgDynOptions = optDynOptions
27− , cfgUnsafe = optUnsafe
28− }
25+ Nothing -> return optConfig
2926 Just path -> do
30− Config {..} <- Yaml.decodeFileThrow path
31− return Config
32− { cfgDynOptions = cfgDynOptions ++ optDynOptions
33− , cfgUnsafe = optUnsafe || cfgUnsafe
34− }
35− r <- ormoluFile config optDebug optInputFile
27+ config <- Yaml.decodeFileThrow path
28+ return (config <> optConfig)
29+ r <- ormoluFile config optInputFile
3630 case optMode of
3731 Stdout ->
3832 TIO.putStr r
@@ -50,12 +44,8 @@ data Opts = Opts
5044 -- ^ Mode of operation
5145 , optConfigFile :: !(Maybe FilePath)
5246 -- ^ Location of configuration file (optional)
53− , optUnsafe :: !Bool
54− -- ^ Whether to skip sanity checking
55− , optDynOptions :: ![DynOption]
56− -- ^ GHC options to set
57− , optDebug :: !Bool
58− -- ^ Output information useful for debugging
47+ , optConfig :: !Config
48+ -- ^ Ormolu 'Config'
5949 , optInputFile :: !FilePath
6050 -- ^ Input source file
6151 }
@@ -108,26 +98,30 @@ optsParser = Opts
10898 , metavar "CONFIG"
10999 , help "Location of configuration file"
110100 ]
111− <*> (switch . mconcat)
112− [ long "unsafe"
113− , short 'u'
114− , help "Do formatting faster but without automatic detection of defects"
101+ <*> configParser
102+ <*> (strArgument . mconcat)
103+ [ metavar "FILE"
104+ , help "Haskell source file to format"
115105 ]
116− <*> (fmap (fmap DynOption) . many . strOption . mconcat)
106+
107+configParser :: Parser Config
108+configParser = Config
109+ <$> (fmap (fmap DynOption) . many . strOption . mconcat)
117110 [ long "ghc-opt"
118111 , short 'o'
119112 , metavar "OPT"
120113 , help "GHC options to enable (e.g. language extensions)"
121114 ]
115+ <*> (switch . mconcat)
116+ [ long "unsafe"
117+ , short 'u'
118+ , help "Do formatting faster but without automatic detection of defects"
119+ ]
122120 <*> (switch . mconcat)
123121 [ long "debug"
124122 , short 'd'
125123 , help "Output information useful for debugging"
126124 ]
127− <*> (strArgument . mconcat)
128− [ metavar "FILE"
129− , help "Haskell source file to format"
130− ]
131125
132126----------------------------------------------------------------------------
133127-- Helpers