Permalink
Browse files

cmdline --version info option

  • Loading branch information...
atzedijkstra committed Mar 31, 2014
1 parent 2ced181 commit d9ad38c35daaa3ff16e65f1e51bf194275989393
Showing with 54 additions and 21 deletions.
  1. +25 −1 Setup.hs
  2. +1 −0 shuffle.cabal
  3. +26 −20 src/UHC/Shuffle.hs
  4. +2 −0 src/UHC/Shuffle/Common.hs
View
@@ -2,5 +2,29 @@ import Distribution.Simple (defaultMainWithHooks)
import Distribution.Simple.UUAGC (uuagcLibUserHook)
import UU.UUAGC (uuagc)
+{-
main :: IO ()
-main = defaultMainWithHooks (uuagcLibUserHook uuagc)
+main = defaultMainWithHooks $
+ uuagcLibUserHook uuagc
+-}
+
+{-
+-}
+import Distribution.PackageDescription
+import Distribution.Simple.UserHooks
+import Distribution.Package
+import Data.Version
+
+main :: IO ()
+main = defaultMainWithHooks $
+ addHook $
+ uuagcLibUserHook uuagc
+ where addHook hooks = hooks {
+ postConf = postConf_InsertVersion hooks
+ }
+ -- postConf_InsertVersion :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
+ postConf_InsertVersion hooks args cfg pkgDescr bi = do
+ postConf hooks args cfg pkgDescr bi
+ writeFile "src/UHC/Shuffle/Version.hs" $
+ "module UHC.Shuffle.Version where\n" ++
+ "version = \"" ++ showVersion (pkgVersion $ package pkgDescr) ++ "\"\n"
View
@@ -26,6 +26,7 @@ Library
Hs-Source-Dirs: src
Extensions: RankNTypes, TypeSynonymInstances, FlexibleInstances, FlexibleContexts
Exposed-Modules: UHC.Shuffle,
+ UHC.Shuffle.Version,
Distribution.Simple.Shuffle
Other-Modules: UHC.Shuffle.AspectExpr,
UHC.Shuffle.AspectExprEval,
View
@@ -13,22 +13,23 @@ module UHC.Shuffle (
import qualified Data.Set as Set
import qualified Data.Map as Map
-import Data.Map(Map)
-import Data.Set(Set)
-import System.Exit
-import System.Environment
-import System.IO
-import System.Console.GetOpt
-import UHC.Util.ParseUtils
-import UHC.Util.DependencyGraph
-import UHC.Util.FPath
-import UHC.Util.Pretty
-import UHC.Shuffle.Common
-import UHC.Shuffle.MainAG
-import UHC.Shuffle.ChunkParser
-import UHC.Shuffle.CDoc
-import UHC.Shuffle.CDocSubst
-import Data.Char
+import Data.Map(Map)
+import Data.Set(Set)
+import System.Exit
+import System.Environment
+import System.IO
+import System.Console.GetOpt
+import UHC.Util.ParseUtils
+import UHC.Util.DependencyGraph
+import UHC.Util.FPath
+import UHC.Util.Pretty
+import UHC.Shuffle.Common
+import UHC.Shuffle.MainAG
+import UHC.Shuffle.ChunkParser
+import UHC.Shuffle.CDoc
+import UHC.Shuffle.CDocSubst
+import qualified UHC.Shuffle.Version as Version
+import Data.Char
-------------------------------------------------------------------------
-- main
@@ -42,11 +43,13 @@ shuffleMain
; let (opts,f,frest,errs) = parseOpts args
; if optHelp opts
then putStrLn (usageInfo "Usage shuffle [options] [file ([alias=]file)*|-]\n\noptions:" cmdLineOpts)
+ else if optVersion opts
+ then putStrLn Version.version
else if null errs
- then if optGenDeps opts
- then genDeps f opts
- else shuffleCompile stdout opts f frest >> return ()
- else putStr (head errs)
+ then if optGenDeps opts
+ then genDeps f opts
+ else shuffleCompile stdout opts f frest >> return ()
+ else putStr (head errs)
}
parseOpts :: [String] -> (Opts, FPath, [FPathWithAlias], [String])
@@ -283,6 +286,8 @@ cmdLineOpts
"file with list of strings not to be cross ref'd"
, Option "" ["help"] (NoArg oHelp)
"output this help"
+ , Option "" ["version"] (NoArg oVersion)
+ "output version number"
, Option "" ["dep"] (NoArg oDep)
"output dependencies"
, Option "" ["depnameprefix"] (OptArg oDepNamePrefix "<name>")
@@ -335,6 +340,7 @@ cmdLineOpts
('a':'p':'p':'x':'=':f) -> o {optChDest = (ChHide,f)}
_ -> o
oHelp o = o {optHelp = True}
+ oVersion o = o {optVersion = True}
oDep o = o {optGenDeps = True}
oDepNamePrefix ms o = o { optDepNamePrefix = maybe "FILE_" id ms }
oDepSrcVar ms o = o { optDepSrcVar = maybe "SRC_VAR" id ms }
@@ -132,6 +132,7 @@ data Opts
, optIndex :: Bool
, optCompiler :: [Int]
, optHelp :: Bool
+ , optVersion :: Bool
, optGenDeps :: Bool
, optGenText2Text :: Bool -- include text2text text type annotation
, optChDest :: (ChDest,String)
@@ -166,6 +167,7 @@ defaultOpts
, optIndex = False
, optCompiler = []
, optHelp = False
+ , optVersion = False
, optGenDeps = False
, optGenText2Text = False
, optChDest = (ChHere,"")

0 comments on commit d9ad38c

Please sign in to comment.