@@ -22,17 +22,11 @@ main :: IO ()
22main = withPrettyOrmoluExceptions $ do
22main = withPrettyOrmoluExceptions $ do
23 Opts {..} <- execParser optsParserInfo
23 Opts {..} <- execParser optsParserInfo
24 config <- case optConfigFile of
24 config <- case optConfigFile of
25− Nothing -> return Config
25+ Nothing -> return optConfig
26− { cfgDynOptions = optDynOptions
27− , cfgUnsafe = optUnsafe
29 Just path -> do
26 Just path -> do
30− Config {..} <- Yaml.decodeFileThrow path
27+ config <- Yaml.decodeFileThrow path
31− return Config
28+ return (config <> optConfig)
32− { cfgDynOptions = cfgDynOptions ++ optDynOptions
33− , cfgUnsafe = optUnsafe || cfgUnsafe
35− r <- ormoluFile config optDebug optInputFile
29+ r <- ormoluFile config optInputFile
36 case optMode of
30 case optMode of
38 TIO.putStr r
32 TIO.putStr r
@@ -50,12 +44,8 @@ data Opts = Opts
50 -- ^ Mode of operation
44 -- ^ Mode of operation
51 , optConfigFile :: !(Maybe FilePath)
45 , optConfigFile :: !(Maybe FilePath)
52 -- ^ Location of configuration file (optional)
46 -- ^ Location of configuration file (optional)
53− , optUnsafe :: !Bool
47+ , optConfig :: !Config
54− -- ^ Whether to skip sanity checking
48+ -- ^ Ormolu 'Config'
55− , optDynOptions :: ![DynOption]
56− -- ^ GHC options to set
58− -- ^ Output information useful for debugging
59 , optInputFile :: !FilePath
49 , optInputFile :: !FilePath
60 -- ^ Input source file
50 -- ^ Input source file
@@ -108,26 +98,30 @@ optsParser = Opts
108 , metavar "CONFIG"
98 , metavar "CONFIG"
109 , help "Location of configuration file"
99 , help "Location of configuration file"
111− <*> (switch . mconcat)
102+ <*> (strArgument . mconcat)
112− [ long "unsafe"
103+ [ metavar "FILE"
113− , short 'u'
104+ , help "Haskell source file to format"
114− , help "Do formatting faster but without automatic detection of defects"
107+configParser :: Parser Config
108+configParser = Config
116− <*> (fmap (fmap DynOption) . many . strOption . mconcat)
109+ <$> (fmap (fmap DynOption) . many . strOption . mconcat)
117 [ long "ghc-opt"
110 [ long "ghc-opt"
118 , short 'o'
111 , short 'o'
119 , metavar "OPT"
112 , metavar "OPT"
120 , help "GHC options to enable (e.g. language extensions)"
113 , help "GHC options to enable (e.g. language extensions)"
115+ <*> (switch . mconcat)
118+ , help "Do formatting faster but without automatic detection of defects"
122 <*> (switch . mconcat)
120 <*> (switch . mconcat)
123 [ long "debug"
121 [ long "debug"
124 , short 'd'
122 , short 'd'
125 , help "Output information useful for debugging"
123 , help "Output information useful for debugging"
127− <*> (strArgument . mconcat)
129− , help "Haskell source file to format"
132----------------------------------------------------------------------------
126----------------------------------------------------------------------------
133-- Helpers
127-- Helpers