Permalink
Browse files

Add --version and --numeric-version flags

  • Loading branch information...
1 parent 96a6477 commit afdf716f7f16c8a6127df614c13c447dc773befa @kolmodin kolmodin committed Feb 19, 2009
Showing with 29 additions and 7 deletions.
  1. +29 −7 Main.hs
View
36 Main.hs
@@ -19,7 +19,7 @@ import Distribution.PackageDescription.Configuration
( flattenPackageDescription )
import Distribution.ReadE ( succeedReadE )
import Distribution.Simple.Command -- commandsRun
-import Distribution.Simple.Utils ( die )
+import Distribution.Simple.Utils ( die, cabalVersion )
import qualified Distribution.PackageDescription as Cabal
import qualified Distribution.PackageDescription.Parse as Cabal
import qualified Distribution.Package as Cabal
@@ -52,6 +52,9 @@ import Merge
import Cabal2Ebuild
+import qualified Paths_cabal_install
+import qualified Paths_hackport
+
-----------------------------------------------------------------------
-- List
-----------------------------------------------------------------------
@@ -463,12 +466,14 @@ usageFlags name pname =
-----------------------------------------------------------------------
data GlobalFlags = GlobalFlags {
- globalVersion :: Flag Bool
+ globalVersion :: Flag Bool,
+ globalNumericVersion :: Flag Bool
}
defaultGlobalFlags :: GlobalFlags
defaultGlobalFlags = GlobalFlags {
- globalVersion = Flag False
+ globalVersion = Flag False,
+ globalNumericVersion = Flag False
}
globalCommand :: CommandUI GlobalFlags
@@ -480,7 +485,15 @@ globalCommand = CommandUI {
commandUsage = \_ -> [],
commandDefaultFlags = defaultGlobalFlags,
commandOptions = \showOrParseArgs ->
- [ ]
+ [ option ['V'] ["version"]
+ "Print version information"
+ globalVersion (\v flags -> flags { globalVersion = v })
+ trueArg
+ , option [] ["numeric-version"]
+ "Print just the version number"
+ globalNumericVersion (\v flags -> flags { globalNumericVersion = v })
+ trueArg
+ ]
}
mainWorker :: [String] -> IO ()
@@ -491,16 +504,25 @@ mainWorker args =
CommandErrors errs -> printErrors errs
CommandReadyToGo (globalflags, commandParse) -> do
case commandParse of
- CommandHelp help -> printHelp help
- CommandList opts -> printOptionsList opts
- CommandErrors errs -> printErrors errs
+ _ | fromFlag (globalVersion globalflags) -> printVersion
+ | fromFlag (globalNumericVersion globalflags) -> printNumericVersion
+ CommandHelp help -> printHelp help
+ CommandList opts -> printOptionsList opts
+ CommandErrors errs -> printErrors errs
CommandReadyToGo action -> catchEx (action globalflags) errorHandler
where
printHelp help = getProgName >>= putStr . help
printOptionsList = putStr . unlines
printErrors errs = do
putStr (concat (intersperse "\n" errs))
exitFailure
+ printNumericVersion = putStrLn $ display Paths_hackport.version
+ printVersion = putStrLn $ "hackport version "
+ ++ display Paths_hackport.version
+ ++ "\nusing cabal-install "
+ ++ display Paths_cabal_install.version
+ ++ " and the Cabal library version "
+ ++ display cabalVersion
errorHandler :: HackPortError -> IO ()
errorHandler e = do
putStrLn (hackPortShowError e)

0 comments on commit afdf716

Please sign in to comment.