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
|
-- | The basic numeric type used in amounts. Different implementations
|
||||||
-- can be selected via cabal flag for testing and benchmarking purposes.
|
-- can be selected via cabal flag for testing and benchmarking purposes.
|
||||||
|
numberRepresentation :: String
|
||||||
#ifdef DOUBLE
|
#ifdef DOUBLE
|
||||||
type Quantity = Double
|
type Quantity = Double
|
||||||
|
numberRepresentation = "Double"
|
||||||
#else
|
#else
|
||||||
type Quantity = Decimal
|
type Quantity = Decimal
|
||||||
deriving instance Data (Quantity)
|
deriving instance Data (Quantity)
|
||||||
@ -62,6 +64,7 @@ deriving instance Data (Quantity)
|
|||||||
instance ToMarkup (Quantity)
|
instance ToMarkup (Quantity)
|
||||||
where
|
where
|
||||||
toMarkup = toMarkup . show
|
toMarkup = toMarkup . show
|
||||||
|
numberRepresentation = "Decimal"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-- | An amount's price (none, per unit, or total) in another commodity.
|
-- | 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:
|
-- flags in the unnamed group, shown last without a heading:
|
||||||
,groupUnnamed = []
|
,groupUnnamed = []
|
||||||
-- flags accepted but not shown in the help:
|
-- 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
|
isBadCommand = not (null rawcmd) && null cmd
|
||||||
hasHelp args = any (`elem` args) ["--help","-h","-?"]
|
hasHelp args = any (`elem` args) ["--help","-h","-?"]
|
||||||
hasVersion = ("--version" `elem`)
|
hasVersion = ("--version" `elem`)
|
||||||
|
hasDetailedVersion = ("--version+" `elem`)
|
||||||
generalHelp = putStr $ showModeHelp $ mainmode addonDisplayNames
|
generalHelp = putStr $ showModeHelp $ mainmode addonDisplayNames
|
||||||
version = putStrLn prognameandversion
|
|
||||||
badCommandError = error' ("command "++rawcmd++" is not recognized, run with no command to see a list") >> exitFailure
|
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
|
f `orShowHelp` mode = if hasHelp args then putStr (showModeHelp mode) else f
|
||||||
dbgM "processed opts" opts
|
dbgM "processed opts" opts
|
||||||
@ -244,7 +246,9 @@ main = do
|
|||||||
-- high priority flags and situations. --help should be highest priority.
|
-- high priority flags and situations. --help should be highest priority.
|
||||||
| hasHelp argsbeforecmd = dbgM "" "--help before command, showing general help" >> generalHelp
|
| hasHelp argsbeforecmd = dbgM "" "--help before command, showing general help" >> generalHelp
|
||||||
| not (hasHelp argsaftercmd) && (hasVersion argsbeforecmd || (hasVersion argsaftercmd && isInternalCommand))
|
| 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
|
-- \| (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 = dbgM "" "no command, showing general help" >> generalHelp
|
| isNullCommand = dbgM "" "no command, showing general help" >> generalHelp
|
||||||
|
@ -10,6 +10,7 @@ module Hledger.Cli.Options (
|
|||||||
|
|
||||||
-- * cmdargs flags & modes
|
-- * cmdargs flags & modes
|
||||||
helpflags,
|
helpflags,
|
||||||
|
detailedversionflag,
|
||||||
inputflags,
|
inputflags,
|
||||||
reportflags,
|
reportflags,
|
||||||
generalflagsgroup1,
|
generalflagsgroup1,
|
||||||
@ -85,6 +86,10 @@ helpflags = [
|
|||||||
,flagNone ["version"] (setboolopt "version") "show version information"
|
,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...
|
-- | Common input-related flags: --file, --rules-file, --alias...
|
||||||
inputflags :: [Flag RawOpts]
|
inputflags :: [Flag RawOpts]
|
||||||
inputflags = [
|
inputflags = [
|
||||||
|
@ -7,17 +7,19 @@ module Hledger.Cli.Version (
|
|||||||
progname,
|
progname,
|
||||||
version,
|
version,
|
||||||
prognameandversion,
|
prognameandversion,
|
||||||
|
prognameanddetailedversion,
|
||||||
binaryfilename
|
binaryfilename
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import System.Info (os, arch)
|
import System.Info (os, arch)
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
|
import Hledger.Data.Types (numberRepresentation)
|
||||||
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 :: String
|
progname, version, prognameandversion, prognameanddetailedversion :: String
|
||||||
progname = "hledger"
|
progname = "hledger"
|
||||||
#ifdef VERSION
|
#ifdef VERSION
|
||||||
version = VERSION
|
version = VERSION
|
||||||
@ -25,6 +27,7 @@ version = VERSION
|
|||||||
version = ""
|
version = ""
|
||||||
#endif
|
#endif
|
||||||
prognameandversion = progname ++ " " ++ version
|
prognameandversion = progname ++ " " ++ version
|
||||||
|
prognameanddetailedversion = printf "%s %s, using %s" progname version numberRepresentation
|
||||||
|
|
||||||
-- 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user