Skip to content

Commit

Permalink
Allow formatting of multiple files.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Nov 4, 2024
1 parent b061618 commit 09c4284
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Futhark/CLI/Fmt.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- | @futhark fmt@
module Futhark.CLI.Fmt (main) where

import Control.Monad (forM_)
import Data.Text.IO qualified as T
import Futhark.Fmt.Printer
import Futhark.Util.Options
Expand All @@ -12,15 +13,13 @@ import System.IO

-- | Run @futhark fmt@.
main :: String -> [String] -> IO ()
main = mainWithOptions () [] "program" $ \args () ->
main = mainWithOptions () [] "[FILES" $ \args () ->
case args of
[] -> Just $ putDoc =<< onInput =<< T.getContents
[file] ->
Just $ do
files ->
Just $ forM_ files $ \file -> do
doc <- onInput =<< T.readFile file
withFile file WriteMode $ \h ->
hPutDoc h doc
_any -> Nothing
withFile file WriteMode $ \h -> hPutDoc h doc
where
onInput s = do
case fmtToDoc "<stdin>" s of
Expand Down

0 comments on commit 09c4284

Please sign in to comment.