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