allow an optional level argument with --debug

This commit is contained in:
Simon Michael 2013-12-06 13:30:36 -08:00
parent 6e7610c1b7
commit c99f37241c
3 changed files with 7 additions and 8 deletions

View File

@ -264,7 +264,7 @@ journalAddTransaction :: Journal -> CliOpts -> Transaction -> IO Journal
journalAddTransaction j@Journal{jtxns=ts} opts t = do
let f = journalFilePath j
appendToJournalFileOrStdout f $ showTransaction t
when (debug_ opts) $ do
when (debug_ opts > 0) $ do
putStrLn $ printf "\nAdded transaction to %s:" f
putStrLn =<< registerFromString (show t)
return j{jtxns=ts++[t]}

View File

@ -125,7 +125,7 @@ main = do
putStrLn $ "interval from opts: " ++ (show $ intervalFromOpts $ reportopts_ opts)
putStrLn $ "query from opts & args: " ++ (show $ queryFromOpts d $ reportopts_ opts)
let
dbg s = if debug_ opts then trace s else id
dbg s = if debug_ opts > 0 then trace s else id
runHledgerCommand
-- high priority flags and situations. --help should be highest priority.
| hasHelp argsbeforecmd = dbg "--help before command, showing general help" generalHelp
@ -151,7 +151,7 @@ main = do
-- an external command
| isExternalCommand = do
let shellcmd = printf "%s-%s %s" progname cmd (unwords' argsaftercmd)
when (debug_ opts) $ do
when (debug_ opts > 0) $ do
printf "external command selected: %s\n" cmd
printf "external command arguments: %s\n" (show argsaftercmd)
printf "running shell command: %s\n" (show shellcmd)

View File

@ -106,7 +106,6 @@ import Hledger
import Hledger.Data.FormatStrings as Format
import Hledger.Cli.Version
--
-- 1. cmdargs mode and flag (option) definitions for the hledger CLI,
-- can be reused by other packages as well.
@ -121,7 +120,7 @@ type RawOpts = [(String,String)]
helpflags = [
flagNone ["help","h","?"] (setboolopt "help") "Display general help or (with --help after COMMAND) command help."
-- ,flagNone ["browse-args"] (setboolopt "browse-args") "use a web UI to select options and build up a command line"
,flagNone ["debug"] (setboolopt "debug") "Show extra debug output"
,flagOpt "1" ["debug"] (\s opts -> Right $ setopt "debug" s opts) "N" "Show debug output (optional argument sets debug level)"
,flagNone ["version","V"] (setboolopt "version") "Print version information"
]
@ -410,14 +409,14 @@ convertmode = (defCommandMode ["convert"]) {
-- completed, but before adding defaults or derived values (XXX add)
--
-- cli options, used in hledger and above
-- | Command line options. Used in the @hledger@ package and above.
data CliOpts = CliOpts {
rawopts_ :: RawOpts
,command_ :: String
,file_ :: Maybe FilePath
,rules_file_ :: Maybe FilePath
,alias_ :: [String]
,debug_ :: Bool
,debug_ :: Int -- ^ debug level, set by @--debug[=N]@. See also 'Hledger.Utils.debugLevel'.
,no_new_accounts_ :: Bool -- add
,width_ :: Maybe String -- register
,reportopts_ :: ReportOpts
@ -448,7 +447,7 @@ rawOptsToCliOpts rawopts = do
,file_ = maybestringopt "file" rawopts
,rules_file_ = maybestringopt "rules-file" rawopts
,alias_ = map stripquotes $ listofstringopt "alias" rawopts
,debug_ = boolopt "debug" rawopts
,debug_ = intopt "debug" rawopts
,no_new_accounts_ = boolopt "no-new-accounts" rawopts -- add
,width_ = maybestringopt "width" rawopts -- register
,reportopts_ = defreportopts {