mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 18:29:36 +03:00
cli: add a hidden --version+ flag showing number representation (#118)
This commit is contained in:
parent
3b70362525
commit
e8a58d9388
@ -52,8 +52,10 @@ type Commodity = String
|
||||
|
||||
-- | The basic numeric type used in amounts. Different implementations
|
||||
-- can be selected via cabal flag for testing and benchmarking purposes.
|
||||
numberRepresentation :: String
|
||||
#ifdef DOUBLE
|
||||
type Quantity = Double
|
||||
numberRepresentation = "Double"
|
||||
#else
|
||||
type Quantity = Decimal
|
||||
deriving instance Data (Quantity)
|
||||
@ -62,6 +64,7 @@ deriving instance Data (Quantity)
|
||||
instance ToMarkup (Quantity)
|
||||
where
|
||||
toMarkup = toMarkup . show
|
||||
numberRepresentation = "Decimal"
|
||||
#endif
|
||||
|
||||
-- | An amount's price (none, per unit, or total) in another commodity.
|
||||
|
@ -111,7 +111,9 @@ mainmode addons = defMode {
|
||||
-- flags in the unnamed group, shown last without a heading:
|
||||
,groupUnnamed = []
|
||||
-- flags accepted but not shown in the help:
|
||||
,groupHidden = inputflags -- included here so they'll not raise a confusing error if present with no COMMAND
|
||||
,groupHidden =
|
||||
detailedversionflag :
|
||||
inputflags -- included here so they'll not raise a confusing error if present with no COMMAND
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,8 +227,8 @@ main = do
|
||||
isBadCommand = not (null rawcmd) && null cmd
|
||||
hasHelp args = any (`elem` args) ["--help","-h","-?"]
|
||||
hasVersion = ("--version" `elem`)
|
||||
hasDetailedVersion = ("--version+" `elem`)
|
||||
generalHelp = putStr $ showModeHelp $ mainmode addonDisplayNames
|
||||
version = putStrLn prognameandversion
|
||||
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure
|
||||
f `orShowHelp` mode = if hasHelp args then putStr (showModeHelp mode) else f
|
||||
dbgM "processed opts" opts
|
||||
@ -244,7 +246,9 @@ main = do
|
||||
-- high priority flags and situations. --help should be highest priority.
|
||||
| hasHelp argsbeforecmd = dbgM "" "--help before command, showing general help" >> generalHelp
|
||||
| not (hasHelp argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
|
||||
= version
|
||||
= putStrLn prognameandversion
|
||||
| not (hasHelp argsaftercmd) && (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 = dbgM "" "no command, showing general help" >> generalHelp
|
||||
|
@ -10,6 +10,7 @@ module Hledger.Cli.Options (
|
||||
|
||||
-- * cmdargs flags & modes
|
||||
helpflags,
|
||||
detailedversionflag,
|
||||
inputflags,
|
||||
reportflags,
|
||||
generalflagsgroup1,
|
||||
@ -85,6 +86,10 @@ helpflags = [
|
||||
,flagNone ["version"] (setboolopt "version") "show version information"
|
||||
]
|
||||
|
||||
-- | A hidden flag, just for the hledger executable.
|
||||
detailedversionflag :: Flag RawOpts
|
||||
detailedversionflag = flagNone ["version+"] (setboolopt "version+") "show version information with extra detail"
|
||||
|
||||
-- | Common input-related flags: --file, --rules-file, --alias...
|
||||
inputflags :: [Flag RawOpts]
|
||||
inputflags = [
|
||||
|
@ -7,17 +7,19 @@ module Hledger.Cli.Version (
|
||||
progname,
|
||||
version,
|
||||
prognameandversion,
|
||||
prognameanddetailedversion,
|
||||
binaryfilename
|
||||
)
|
||||
where
|
||||
import System.Info (os, arch)
|
||||
import Text.Printf
|
||||
|
||||
import Hledger.Data.Types (numberRepresentation)
|
||||
import Hledger.Utils
|
||||
|
||||
|
||||
-- package name and version from the cabal file
|
||||
progname, version, prognameandversion :: String
|
||||
progname, version, prognameandversion, prognameanddetailedversion :: String
|
||||
progname = "hledger"
|
||||
#ifdef VERSION
|
||||
version = VERSION
|
||||
@ -25,6 +27,7 @@ version = VERSION
|
||||
version = ""
|
||||
#endif
|
||||
prognameandversion = progname ++ " " ++ version
|
||||
prognameanddetailedversion = printf "%s %s, using %s" progname version numberRepresentation
|
||||
|
||||
-- developer build version strings include PATCHLEVEL (number of
|
||||
-- patches since the last tag). If defined, it must be a number.
|
||||
|
Loading…
Reference in New Issue
Block a user