@@ -23,30 +23,43 @@ import qualified Data.Text.IO as TIO
2323main :: IO ()
2424main = withPrettyOrmoluExceptions $ do
2525 Opts {..} <- execParser optsParserInfo
26− r <- case optInputFile of
27− "-" -> ormoluStdin optConfig
28− inputFile -> ormoluFile optConfig inputFile
29− let notForStdin = do
30− when (optInputFile == "-") $ do
31− hPutStrLn
32− stderr
33− "This feature is not supported when input comes from stdin."
26+ let formatOne' = formatOne optMode optConfig
27+ case optInputFiles of
28+ [] -> formatOne' Nothing
29+ ["-"] -> formatOne' Nothing
30+ xs -> mapM_ (formatOne' . Just) xs
31+
32+-- | Format a single input.
33+
34+formatOne
35+ :: Mode -- ^ Mode of operation
36+ -> Config -- ^ Configuration
37+ -> Maybe FilePath -- ^ File to format or stdin as 'Nothing'
38+ -> IO ()
39+formatOne mode config = \case
40+ Nothing -> do
41+ r <- ormoluStdin config
42+ case mode of
43+ Stdout -> TIO.putStr r
44+ _ -> do
45+ hPutStrLn stderr
46+ "This feature is not supported when input comes from stdin."
3447 -- 101 is different from all the other exit codes we already use.
35− exitWith (ExitFailure 101)
36− case optMode of
37− Stdout ->
38− TIO.putStr r
39− InPlace -> do
40− notForStdin
41− TIO.writeFile optInputFile r
42− Check -> do
43− notForStdin
44− r' <- TIO.readFile optInputFile
45− when (r /= r') $
46− -- 100 is different to all the other exit code that are emitted
47− -- either from an 'OrmoluException' or from 'error' and
48− -- 'notImplemented'.
49− exitWith (ExitFailure 100)
48+ exitWith (ExitFailure 101)
49+ Just inputFile -> do
50+ r <- ormoluFile config inputFile
51+ case mode of
52+ Stdout ->
53+ TIO.putStr r
54+ InPlace ->
55+ TIO.writeFile inputFile r
56+ Check -> do
57+ r' <- TIO.readFile inputFile
58+ when (r /= r') $
59+ -- 100 is different to all the other exit code that are emitted
60+ -- either from an 'OrmoluException' or from 'error' and
61+ -- 'notImplemented'.
62+ exitWith (ExitFailure 100)
5063
5164----------------------------------------------------------------------------
5265-- Command line options parsing.
@@ -56,8 +69,8 @@ data Opts = Opts
5669 -- ^ Mode of operation
5770 , optConfig :: !Config
5871 -- ^ Ormolu 'Config'
59− , optInputFile :: !FilePath
60− -- ^ Input source file or stdin ("-")
72+ , optInputFiles :: ![FilePath]
73+ -- ^ Haskell source files to format or stdin (when the list is empty)
6174 }
6275
6376-- | Mode of operation.
@@ -108,10 +121,9 @@ optsParser = Opts
108121 , help "Mode of operation: 'stdout', 'inplace', or 'check'"
109122 ]
110123 <*> configParser
111− <*> (strArgument . mconcat)
124+ <*> (many . strArgument . mconcat)
112125 [ metavar "FILE"
113− , value "-"
114− , help "Haskell source file to format or stdin (default)"
126+ , help "Haskell source files to format or stdin (default)"
115127 ]
116128
117129configParser :: Parser Config