conffmt (empty) → 0.2.3.0
raw patch · 4 files changed
+110/−0 lines, 4 filesdep +basedep +language-confdep +megaparsecsetup-changed
Dependencies added: base, language-conf, megaparsec, optparse-applicative, pretty, text
Files
- LICENSE +21/−0
- Setup.hs +2/−0
- bin/ConfFmt.hs +52/−0
- conffmt.cabal +35/−0
+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2016 Pedro Tacla Yamada++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bin/ConfFmt.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE RecordWildCards #-}+import Control.Monad+import qualified Data.Conf as Conf+import qualified Data.Text.IO as Text (hGetContents, readFile)+import Options.Applicative+import Options.Applicative.Types+import System.Environment (getArgs)+import System.Exit (exitFailure)+import System.IO+import qualified Text.Megaparsec as Megaparsec++data ConfFmtOptions+ = ConfFmtOptions { cfoInplace :: Bool+ , cfoOutput :: Maybe FilePath+ , cfoInput :: Maybe FilePath+ }++options :: Parser ConfFmtOptions+options = ConfFmtOptions+ <$> cfoInplaceAP+ <*> cfoOutputAP+ <*> cfoInputAP++cfoInputAP = optional (argument str+ (metavar "INPUTFILE"+ <> help "The input file (omission will cause `conffmt` to use stdin)"))++cfoOutputAP = optional (option str (short 'o' <> long "output"))+cfoInplaceAP = switch (long "inplace"+ <> short 'i'+ <> help "Format the FILE inplace, replacing it's contents")++main :: IO ()+main = do+ ConfFmtOptions{..} <- execParser (info (helper <*> options)+ ( fullDesc+ <> progDesc "Format a .conf FILE"+ <> header "conffmt - Conf formatter using Haskell language-conf"+ ))+ (contents, fp) <- case cfoInput of+ Just fp ->+ (,) <$> Text.readFile fp <*> pure fp+ Nothing ->+ (,) <$> Text.hGetContents stdin <*> pure "<stdin>"+ case Megaparsec.parse Conf.conf fp contents of+ Left err -> hPrint stderr err+ Right ast -> do+ let output = show (Conf.pPrintConf ast)+ case (cfoInplace, cfoOutput) of+ (_, Just outputFp) -> writeFile outputFp output+ (True, _) -> writeFile fp output+ _ -> putStr output
+ conffmt.cabal view
@@ -0,0 +1,35 @@+-- This file has been generated from package.yaml by hpack version 0.14.0.+--+-- see: https://github.com/sol/hpack++name: conffmt+version: 0.2.3.0+synopsis: A .conf file formatter+description: "conffmt" is a @.conf@ file formatter that serves as an example of @language-conf@ +category: Data+homepage: https://github.com/beijaflor-io/haskell-language-conf#readme+bug-reports: https://github.com/beijaflor-io/haskell-language-conf/issues+author: Pedro Tacla Yamada+maintainer: tacla.yamada@gmail.com+copyright: Copyright (c) 2016 Pedro Tacla Yamada+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++source-repository head+ type: git+ location: https://github.com/beijaflor-io/haskell-language-conf++executable conffmt+ main-is: ConfFmt.hs+ hs-source-dirs:+ bin+ build-depends:+ base >=4 && <5+ , text+ , optparse-applicative+ , megaparsec+ , language-conf+ , pretty+ default-language: Haskell2010