show args processing debug output only at level 2+

This commit is contained in:
Simon Michael 2014-04-02 04:48:10 -07:00
parent a05810f8e0
commit a1531bcd09

View File

@ -1,3 +1,4 @@
{-# LANGUAGE NoMonomorphismRestriction #-} -- for dbgM
{-| {-|
hledger - a ledger-compatible accounting tool. hledger - a ledger-compatible accounting tool.
Copyright (c) 2007-2011 Simon Michael <simon@joyful.com> Copyright (c) 2007-2011 Simon Michael <simon@joyful.com>
@ -38,7 +39,7 @@ See "Hledger.Data.Ledger" for more examples.
module Hledger.Cli.Main where module Hledger.Cli.Main where
import Control.Monad -- import Control.Monad
import Data.Char (isDigit) import Data.Char (isDigit)
import Data.List import Data.List
import Safe import Safe
@ -186,13 +187,17 @@ 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 (debugLevel > 0) $ do
printf "running: %s\n" prognameandversion dbglevel = 2
printf "raw args: %s\n" (show args) dbg = dbgAt dbglevel
printf "raw args rearranged for cmdargs: %s\n" (show args') dbgM = \a b -> dbg a b `seq` return () -- requires NoMonomorphismRestriction
printf "raw command is probably: %s\n" (show rawcmd)
printf "raw args before command: %s\n" (show argsbeforecmd) dbgM "running" prognameandversion
printf "raw args after command: %s\n" (show argsaftercmd) dbgM "raw args" args
dbgM "raw args rearranged for cmdargs" args'
dbgM "raw command is probably" rawcmd
dbgM "raw args before command" argsbeforecmd
dbgM "raw args after command" argsaftercmd
-- search PATH for add-ons -- search PATH for add-ons
addons <- getHledgerAddonCommands addons <- getHledgerAddonCommands
@ -213,27 +218,25 @@ main = do
version = putStrLn prognameandversion 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
when (debug_ opts > 0) $ do dbgM "processed opts" opts
putStrLn $ "processed opts:\n" ++ ppShow opts dbgM "command matched" cmd
putStrLn $ "command matched: " ++ show cmd dbgM "isNullCommand" isNullCommand
putStrLn $ "isNullCommand: " ++ show isNullCommand dbgM "isInternalCommand" isInternalCommand
putStrLn $ "isInternalCommand: " ++ show isInternalCommand dbgM "isExternalCommand" isExternalCommand
putStrLn $ "isExternalCommand: " ++ show isExternalCommand dbgM "isBadCommand" isBadCommand
putStrLn $ "isBadCommand: " ++ show isBadCommand d <- getCurrentDay
d <- getCurrentDay dbgM "date span from opts" (dateSpanFromOpts d $ reportopts_ opts)
putStrLn $ "date span from opts: " ++ (show $ dateSpanFromOpts d $ reportopts_ opts) dbgM "interval from opts" (intervalFromOpts $ reportopts_ opts)
putStrLn $ "interval from opts: " ++ (show $ intervalFromOpts $ reportopts_ opts) dbgM "query from opts & args" (queryFromOpts d $ reportopts_ opts)
putStrLn $ "query from opts & args: " ++ (show $ queryFromOpts d $ reportopts_ opts)
let let
dbg s = if debug_ opts > 0 then trace s else id
runHledgerCommand runHledgerCommand
-- high priority flags and situations. --help should be highest priority. -- high priority flags and situations. --help should be highest priority.
| hasHelp argsbeforecmd = dbg "--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 = version
-- \| (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 = dbg "no command, showing general help" generalHelp | isNullCommand = dbgM "" "no command, showing general help" >> generalHelp
| isBadCommand = badCommandError | isBadCommand = badCommandError
-- internal commands -- internal commands
@ -250,11 +253,10 @@ main = do
-- an external command -- an external command
| isExternalCommand = do | isExternalCommand = do
let shellcmd = printf "%s-%s %s" progname cmd (unwords' argsaftercmd) let shellcmd = printf "%s-%s %s" progname cmd (unwords' argsaftercmd) :: String
when (debug_ opts > 0) $ do dbgM "external command selected" cmd
printf "external command selected: %s\n" cmd dbgM "external command arguments" argsaftercmd
printf "external command arguments: %s\n" (show argsaftercmd) dbgM "running shell command" shellcmd
printf "running shell command: %s\n" (show shellcmd)
system shellcmd >>= exitWith system shellcmd >>= exitWith
-- deprecated commands -- deprecated commands