mirror of
https://github.com/serokell/xrefcheck.git
synced 2024-10-26 23:43:41 +03:00
b30413dd41
Problem: xrefcheck does not allow to print the config to stdout instead of writing it to a file. Also, it is easy to overwrite your changes by mistake by executing the command again. Solution: provide a --stdout flag to print the config to stdout, and do not write it to a file unless a --force flag has been included.
31 lines
879 B
Haskell
31 lines
879 B
Haskell
{- SPDX-FileCopyrightText: 2018-2019 Serokell <https://serokell.io>
|
|
-
|
|
- SPDX-License-Identifier: MPL-2.0
|
|
-}
|
|
|
|
module Main where
|
|
|
|
import Universum
|
|
|
|
import Main.Utf8 (withUtf8)
|
|
import System.IO.CodePage (withCP65001)
|
|
|
|
import System.Directory (doesFileExist)
|
|
import Xrefcheck.CLI (Command (..), DumpConfigMode (..), getCommand)
|
|
import Xrefcheck.Command (defaultAction)
|
|
import Xrefcheck.Config (defConfigText)
|
|
|
|
main :: IO ()
|
|
main = withUtf8 $ withCP65001 $ do
|
|
command <- getCommand
|
|
case command of
|
|
DefaultCommand options ->
|
|
defaultAction options
|
|
DumpConfig repoType (DCMFile forceFlag path) -> do
|
|
whenM ((not forceFlag &&) <$> doesFileExist path) do
|
|
putTextLn "Output file exists. Use --force to overwrite."
|
|
exitFailure
|
|
writeFile path (defConfigText repoType)
|
|
DumpConfig repoType DCMStdout ->
|
|
putStr (defConfigText repoType)
|