cli,ui,web: Display full git description in --version report if able.
Remove unused prognameanddetailedversion code branches.
This commit is contained in:
parent
1e2ff1315b
commit
bf063e4538
@ -13,15 +13,14 @@ import System.Environment
|
||||
import Hledger.Cli hiding (progname,version,prognameandversion)
|
||||
import Hledger.UI.Theme (themeNames)
|
||||
|
||||
progname, version :: String
|
||||
progname, version, prognameandversion :: String
|
||||
progname = "hledger-ui"
|
||||
#ifdef VERSION
|
||||
version = VERSION
|
||||
#else
|
||||
version = ""
|
||||
#endif
|
||||
prognameandversion :: String
|
||||
prognameandversion = progname ++ " " ++ version :: String
|
||||
prognameandversion = versiondescription progname
|
||||
|
||||
uiflags = [
|
||||
-- flagNone ["debug-ui"] (setboolopt "rules-file") "run with no terminal output, showing console"
|
||||
|
||||
@ -27,7 +27,7 @@ version = VERSION
|
||||
version = ""
|
||||
#endif
|
||||
prognameandversion :: String
|
||||
prognameandversion = progname ++ " " ++ version :: String
|
||||
prognameandversion = versiondescription progname
|
||||
|
||||
webflags :: [Flag RawOpts]
|
||||
webflags =
|
||||
|
||||
@ -138,7 +138,6 @@ main = do
|
||||
isExternalCommand = not (null cmd) && cmd `elem` addons -- probably
|
||||
isBadCommand = not (null rawcmd) && null cmd
|
||||
hasVersion = ("--version" `elem`)
|
||||
hasDetailedVersion = ("--version+" `elem`)
|
||||
printUsage = putStr $ showModeUsage $ mainmode addons
|
||||
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure -- PARTIAL:
|
||||
hasHelpFlag args = any (`elem` args) ["-h","--help"]
|
||||
@ -170,9 +169,6 @@ main = do
|
||||
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
|
||||
&& (hasVersion args) -- || (hasVersion argsaftercmd && isInternalCommand))
|
||||
= putStrLn prognameandversion
|
||||
| not (isExternalCommand || hasHelpFlag args || hasInfoFlag args || hasManFlag args)
|
||||
&& (hasDetailedVersion argsbeforecmd) -- || (hasDetailedVersion argsaftercmd && isInternalCommand))
|
||||
= putStrLn prognameanddetailedversion
|
||||
-- \| (null externalcmd) && "binary-filename" `inRawOpts` rawopts = putStrLn $ binaryfilename progname
|
||||
-- \| "--browse-args" `elem` args = System.Console.CmdArgs.Helper.execute "cmdargs-browser" mainmode' args >>= (putStr . show)
|
||||
| isNullCommand = dbgIO "" "no command, showing commands list" >> printCommandsList addons
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE CPP, TemplateHaskell #-}
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-
|
||||
Version number-related utilities. See also the Makefile.
|
||||
-}
|
||||
@ -7,26 +8,29 @@ module Hledger.Cli.Version (
|
||||
progname,
|
||||
version,
|
||||
prognameandversion,
|
||||
prognameanddetailedversion,
|
||||
binaryfilename
|
||||
versiondescription,
|
||||
binaryfilename,
|
||||
)
|
||||
where
|
||||
import System.Info (os, arch)
|
||||
import Text.Printf
|
||||
|
||||
#if MIN_VERSION_githash(0,1,4)
|
||||
import GitHash (giDescribe, tGitInfoCwdTry)
|
||||
#else
|
||||
import GitHash (giHash, tGitInfoCwdTry)
|
||||
#endif
|
||||
import System.Info (os, arch)
|
||||
import Hledger.Utils
|
||||
|
||||
|
||||
-- package name and version from the cabal file
|
||||
progname, version, prognameandversion, prognameanddetailedversion :: String
|
||||
progname, version, prognameandversion :: String
|
||||
progname = "hledger"
|
||||
#ifdef VERSION
|
||||
version = VERSION
|
||||
#else
|
||||
version = "dev build"
|
||||
#endif
|
||||
prognameandversion = progname ++ " " ++ version
|
||||
prognameanddetailedversion = printf "%s %s" progname version
|
||||
prognameandversion = versiondescription progname
|
||||
|
||||
-- developer build version strings include PATCHLEVEL (number of
|
||||
-- patches since the last tag). If defined, it must be a number.
|
||||
@ -39,29 +43,40 @@ patchlevel = ""
|
||||
|
||||
-- the package version plus patchlevel if specified
|
||||
buildversion :: String
|
||||
buildversion = version ++ patchlevel
|
||||
|
||||
-- | Given a program name, return a precise platform-specific executable
|
||||
-- name suitable for naming downloadable binaries. Can raise an error if
|
||||
-- the version and patch level was not defined correctly at build time.
|
||||
binaryfilename :: String -> String
|
||||
binaryfilename progname = prettify $ splitAtElement '.' buildversion
|
||||
buildversion = prettify . splitAtElement '.' $ version ++ patchlevel
|
||||
where
|
||||
prettify (major:minor:bugfix:patches:[]) =
|
||||
printf "%s-%s.%s%s%s-%s-%s%s" progname major minor bugfix' patches' os' arch suffix
|
||||
major ++ "." ++ minor ++ bugfix' ++ patches'
|
||||
where
|
||||
bugfix'
|
||||
| bugfix `elem` ["0"{-,"98","99"-}] = ""
|
||||
| otherwise = '.' : bugfix
|
||||
patches'
|
||||
| patches/="0" = '+' : patches
|
||||
| otherwise = ""
|
||||
(os',suffix)
|
||||
| os == "darwin" = ("mac","" :: String)
|
||||
| os == "mingw32" = ("windows",".exe")
|
||||
| otherwise = (os,"")
|
||||
bugfix' = if bugfix == "0" then "" else '.' : bugfix
|
||||
patches' = if patches == "0" then "" else '+' : patches
|
||||
prettify (major:minor:bugfix:[]) = prettify [major,minor,bugfix,"0"]
|
||||
prettify (major:minor:[]) = prettify [major,minor,"0","0"]
|
||||
prettify (major:[]) = prettify [major,"0","0","0"]
|
||||
prettify [] = error' "VERSION is empty, please fix" -- PARTIAL:
|
||||
prettify _ = error' "VERSION has too many components, please fix"
|
||||
|
||||
-- | A string representing the version description of the current package
|
||||
versiondescription :: String -> String
|
||||
versiondescription progname = concat
|
||||
#if MIN_VERSION_githash(0,1,4)
|
||||
[progname, " ", either (const buildversion) giDescribe gi, ", ", os', "-", arch]
|
||||
#else
|
||||
[progname, " ", buildversion, either (const "") (\x -> ", git revision " ++ giHash x) gi, ", ", os', "-", arch]
|
||||
#endif
|
||||
where
|
||||
gi = $$tGitInfoCwdTry
|
||||
os' | os == "darwin" = "mac"
|
||||
| os == "mingw32" = "windows"
|
||||
| otherwise = os
|
||||
|
||||
-- | Given a program name, return a precise platform-specific executable
|
||||
-- name suitable for naming downloadable binaries. Can raise an error if
|
||||
-- the version and patch level was not defined correctly at build time.
|
||||
binaryfilename :: String -> String
|
||||
binaryfilename progname = concat
|
||||
[progname, "-", buildversion, "-", os', "-", arch, suffix]
|
||||
where
|
||||
(os',suffix) | os == "darwin" = ("mac","" :: String)
|
||||
| os == "mingw32" = ("windows",".exe")
|
||||
| otherwise = (os,"")
|
||||
|
||||
@ -150,6 +150,7 @@ library
|
||||
, directory
|
||||
, extra >=1.6.3
|
||||
, filepath
|
||||
, githash >=0.1.2
|
||||
, hashable >=1.2.4
|
||||
, haskeline >=0.6
|
||||
, hledger-lib >=1.21.99 && <1.22
|
||||
@ -200,6 +201,7 @@ executable hledger
|
||||
, directory
|
||||
, extra >=1.6.3
|
||||
, filepath
|
||||
, githash >=0.1.2
|
||||
, haskeline >=0.6
|
||||
, hledger
|
||||
, hledger-lib >=1.21.99 && <1.22
|
||||
@ -250,6 +252,7 @@ test-suite unittest
|
||||
, directory
|
||||
, extra >=1.6.3
|
||||
, filepath
|
||||
, githash >=0.1.2
|
||||
, haskeline >=0.6
|
||||
, hledger
|
||||
, hledger-lib >=1.21.99 && <1.22
|
||||
@ -298,6 +301,7 @@ benchmark bench
|
||||
, directory
|
||||
, extra >=1.6.3
|
||||
, filepath
|
||||
, githash >=0.1.2
|
||||
, haskeline >=0.6
|
||||
, hledger
|
||||
, hledger-lib >=1.21.99 && <1.22
|
||||
|
||||
@ -108,6 +108,7 @@ dependencies:
|
||||
- directory
|
||||
- extra >=1.6.3
|
||||
- filepath
|
||||
- githash >=0.1.2
|
||||
- haskeline >=0.6
|
||||
- megaparsec >=7.0.0 && <9.1
|
||||
- mtl >=2.2.1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user