diff --git a/hledger-lib/Hledger/Utils.hs b/hledger-lib/Hledger/Utils.hs index abc409c4c..5e86b62bf 100644 --- a/hledger-lib/Hledger/Utils.hs +++ b/hledger-lib/Hledger/Utils.hs @@ -379,15 +379,19 @@ ptrace msg = do -- | Global debug level, which controls the verbosity of debug output -- 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 --- a higher value (note: not @--debug N@). This uses unsafePerformIO --- and can be accessed from anywhere and before normal command-line --- processing. After command-line processing, it is also available as --- the @debug_@ field of 'Hledger.Cli.Options.CliOpts'. +-- a higher value (note: not @--debug N@ for some reason). This uses +-- unsafePerformIO and can be accessed from anywhere and before normal +-- command-line processing. After command-line processing, it is also +-- available as the @debug_@ field of 'Hledger.Cli.Options.CliOpts'. debugLevel :: Int debugLevel = case snd $ break (=="--debug") args of "--debug":[] -> 1 "--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 args = unsafePerformIO getArgs diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index f53c693b8..c7b94d524 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -86,7 +86,7 @@ main = do isNullCommand = null rawcmd (argsbeforecmd, argsaftercmd') = break (==rawcmd) args argsaftercmd = drop 1 argsaftercmd' - when ("--debug" `elem` args) $ do + when (debugLevel > 0) $ do printf "running: %s\n" prognameandversion printf "raw args: %s\n" (show args) printf "raw args rearranged for cmdargs: %s\n" (show args') diff --git a/hledger/Hledger/Cli/Options.hs b/hledger/Hledger/Cli/Options.hs index 4d80b1291..aba9e84fa 100644 --- a/hledger/Hledger/Cli/Options.hs +++ b/hledger/Hledger/Cli/Options.hs @@ -510,6 +510,7 @@ moveFlagsAfterCommand args = move args 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":a:as) = (move $ a:as) ++ ["--debug"] + move (fv@('-':'-':'d':'e':'b':'u':'g':'=':_):a:as) = (move $ a:as) ++ [fv] move as = as isMovableNoArgFlag a = "-" `isPrefixOf` a && dropWhile (=='-') a `elem` noargflagstomove