try Apple AArch64 again
[cabal.git] / cabal-dev-scripts / src / GenCabalInstallCabal.hs
blob5d6f20bcd438f628da7a886fc1f15e3eda775738
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 module Main (main) where
5 import Control.Exception (SomeException (..), catch, displayException)
6 import GHC.Generics (Generic)
7 import System.Environment (getArgs)
8 import System.Exit (exitFailure)
10 import qualified Zinza as Z
12 withIO :: (Bool -> FilePath -> FilePath -> IO a) -> IO a
13 withIO k = do
14 args <- getArgs
15 case args of
16 [dev',src,tgt]
17 | Just dev <- parseBool dev'
18 -> k dev src tgt `catch` \(SomeException e) -> do
19 putStrLn $ "Exception: " ++ displayException e
20 exitFailure
21 _ -> do
22 putStrLn "Usage cabal run ... source.temeplate.ext target.ext"
23 exitFailure
24 where
25 parseBool "True" = Just True
26 parseBool "False" = Just False
27 parseBool _ = Nothing
30 main :: IO ()
31 main = withIO $ \dev src tgt -> do
32 render <- Z.parseAndCompileTemplateIO src
33 contents <- render $ Z dev ()
34 writeFile tgt contents
36 -------------------------------------------------------------------------------
37 -- Data
38 -------------------------------------------------------------------------------
40 data Z = Z
41 { zDev :: Bool
42 , zUnused :: ()
44 deriving (Generic)
46 instance Z.Zinza Z where
47 toType = Z.genericToTypeSFP
48 toValue = Z.genericToValueSFP
49 fromValue = Z.genericFromValueSFP