three fixes to handle --debug=N like --debug
This commit is contained in:
parent
8bbd22d7ed
commit
8261ac0f56
@ -379,15 +379,19 @@ ptrace msg = do
|
|||||||
-- | Global debug level, which controls the verbosity of debug output
|
-- | Global debug level, which controls the verbosity of debug output
|
||||||
-- on the console. The default is 0 meaning no debug output. The
|
-- on the console. The default is 0 meaning no debug output. The
|
||||||
-- @--debug@ command line flag sets it to 1, or @--debug=N@ sets it to
|
-- @--debug@ command line flag sets it to 1, or @--debug=N@ sets it to
|
||||||
-- a higher value (note: not @--debug N@). This uses unsafePerformIO
|
-- a higher value (note: not @--debug N@ for some reason). This uses
|
||||||
-- and can be accessed from anywhere and before normal command-line
|
-- unsafePerformIO and can be accessed from anywhere and before normal
|
||||||
-- processing. After command-line processing, it is also available as
|
-- command-line processing. After command-line processing, it is also
|
||||||
-- the @debug_@ field of 'Hledger.Cli.Options.CliOpts'.
|
-- available as the @debug_@ field of 'Hledger.Cli.Options.CliOpts'.
|
||||||
debugLevel :: Int
|
debugLevel :: Int
|
||||||
debugLevel = case snd $ break (=="--debug") args of
|
debugLevel = case snd $ break (=="--debug") args of
|
||||||
"--debug":[] -> 1
|
"--debug":[] -> 1
|
||||||
"--debug":n:_ -> readDef 1 n
|
"--debug":n:_ -> readDef 1 n
|
||||||
_ -> 0
|
_ ->
|
||||||
|
case take 1 $ filter ("--debug" `isPrefixOf`) args of
|
||||||
|
['-':'-':'d':'e':'b':'u':'g':'=':v] -> readDef 1 v
|
||||||
|
_ -> 0
|
||||||
|
|
||||||
where
|
where
|
||||||
args = unsafePerformIO getArgs
|
args = unsafePerformIO getArgs
|
||||||
|
|
||||||
|
|||||||
@ -86,7 +86,7 @@ main = do
|
|||||||
isNullCommand = null rawcmd
|
isNullCommand = null rawcmd
|
||||||
(argsbeforecmd, argsaftercmd') = break (==rawcmd) args
|
(argsbeforecmd, argsaftercmd') = break (==rawcmd) args
|
||||||
argsaftercmd = drop 1 argsaftercmd'
|
argsaftercmd = drop 1 argsaftercmd'
|
||||||
when ("--debug" `elem` args) $ do
|
when (debugLevel > 0) $ do
|
||||||
printf "running: %s\n" prognameandversion
|
printf "running: %s\n" prognameandversion
|
||||||
printf "raw args: %s\n" (show args)
|
printf "raw args: %s\n" (show args)
|
||||||
printf "raw args rearranged for cmdargs: %s\n" (show args')
|
printf "raw args rearranged for cmdargs: %s\n" (show args')
|
||||||
|
|||||||
@ -510,6 +510,7 @@ moveFlagsAfterCommand args = move args
|
|||||||
move (fv:a:as) | isMovableReqArgFlagAndValue fv = (move $ a:as) ++ [fv]
|
move (fv:a:as) | isMovableReqArgFlagAndValue fv = (move $ a:as) ++ [fv]
|
||||||
move ("--debug":v:a:as) | not (null v) && all isDigit v = (move $ a:as) ++ ["--debug",v]
|
move ("--debug":v:a:as) | not (null v) && all isDigit v = (move $ a:as) ++ ["--debug",v]
|
||||||
move ("--debug":a:as) = (move $ a:as) ++ ["--debug"]
|
move ("--debug":a:as) = (move $ a:as) ++ ["--debug"]
|
||||||
|
move (fv@('-':'-':'d':'e':'b':'u':'g':'=':_):a:as) = (move $ a:as) ++ [fv]
|
||||||
move as = as
|
move as = as
|
||||||
|
|
||||||
isMovableNoArgFlag a = "-" `isPrefixOf` a && dropWhile (=='-') a `elem` noargflagstomove
|
isMovableNoArgFlag a = "-" `isPrefixOf` a && dropWhile (=='-') a `elem` noargflagstomove
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user