summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2012-06-12 00:56:22 -0700
committerJasper Van der Jeugt <jaspervdj@gmail.com>2012-06-12 00:56:22 -0700
commit5c131d2ac79f158a86e8c8ba22eafd170ab63e3a (patch)
treec91c2cf6cd6080f7bf28e7ba04979388e6c062f7
parent2204fdd63aa79b9a75a080dfb19990838444d029 (diff)
parent01018bc9b3d142fd22aaadc633ca58e98379f9ae (diff)
downloadstylish-haskell-5c131d2ac79f158a86e8c8ba22eafd170ab63e3a.tar.gz
Merge pull request #8 from chrisdone/master
In-place writing of a file
-rw-r--r--src/Main.hs9
-rw-r--r--stylish-haskell.cabal6
2 files changed, 12 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs
index eb331cc..7a33530 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -11,6 +11,8 @@ import Data.List (intercalate)
import Data.Maybe (listToMaybe)
import Data.Version (Version(..))
import System.Console.CmdArgs
+import System.IO.Strict (readFile)
+import Prelude hiding (readFile)
--------------------------------------------------------------------------------
@@ -26,6 +28,7 @@ data StylishArgs = StylishArgs
{ config :: Maybe FilePath
, verbose :: Bool
, defaults :: Bool
+ , inPlace :: Bool
, files :: [FilePath]
} deriving (Data, Show, Typeable)
@@ -36,6 +39,7 @@ stylishArgs = StylishArgs
{ config = Nothing &= typFile &= help "Configuration file"
, verbose = False &= help "Run in verbose mode"
, defaults = False &= help "Dump default config and exit"
+ , inPlace = False &= help "Overwrite the given files in place"
, files = [] &= typFile &= args
} &= summary ("stylish-haskell-" ++ versionString version)
where
@@ -59,7 +63,10 @@ stylishHaskell sa
let steps = configSteps conf
forM_ steps $ \s -> verbose' $ "Enabled " ++ stepName s ++ " step"
contents <- maybe getContents readFile filePath
- putStr $ unlines $ runSteps filePath steps $ lines contents
+ write $ unlines $ runSteps filePath steps $ lines contents
where
verbose' = makeVerbose (verbose sa)
filePath = listToMaybe $ files sa
+ write = maybe putStr
+ (if inPlace sa then writeFile else const putStr)
+ filePath
diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal
index 724ed28..e5f1f25 100644
--- a/stylish-haskell.cabal
+++ b/stylish-haskell.cabal
@@ -52,7 +52,8 @@ Executable stylish-haskell
filepath >= 1.1 && < 1.4,
haskell-src-exts >= 1.13 && < 1.14,
syb >= 0.3 && < 0.4,
- yaml >= 0.7 && < 0.8
+ yaml >= 0.7 && < 0.8,
+ strict >= 0.3 && < 0.4
Test-suite stylish-haskell-tests
Ghc-options: -Wall
@@ -82,7 +83,8 @@ Test-suite stylish-haskell-tests
filepath >= 1.1 && < 1.4,
haskell-src-exts >= 1.13 && < 1.14,
syb >= 0.3 && < 0.4,
- yaml >= 0.7 && < 0.8
+ yaml >= 0.7 && < 0.8,
+ strict >= 0.3 && < 0.4
Source-repository head
Type: git