allow an optional level argument with --debug
This commit is contained in:
parent
6e7610c1b7
commit
c99f37241c
@ -264,7 +264,7 @@ journalAddTransaction :: Journal -> CliOpts -> Transaction -> IO Journal
|
|||||||
journalAddTransaction j@Journal{jtxns=ts} opts t = do
|
journalAddTransaction j@Journal{jtxns=ts} opts t = do
|
||||||
let f = journalFilePath j
|
let f = journalFilePath j
|
||||||
appendToJournalFileOrStdout f $ showTransaction t
|
appendToJournalFileOrStdout f $ showTransaction t
|
||||||
when (debug_ opts) $ do
|
when (debug_ opts > 0) $ do
|
||||||
putStrLn $ printf "\nAdded transaction to %s:" f
|
putStrLn $ printf "\nAdded transaction to %s:" f
|
||||||
putStrLn =<< registerFromString (show t)
|
putStrLn =<< registerFromString (show t)
|
||||||
return j{jtxns=ts++[t]}
|
return j{jtxns=ts++[t]}
|
||||||
|
|||||||
@ -125,7 +125,7 @@ main = do
|
|||||||
putStrLn $ "interval from opts: " ++ (show $ intervalFromOpts $ reportopts_ opts)
|
putStrLn $ "interval from opts: " ++ (show $ intervalFromOpts $ reportopts_ opts)
|
||||||
putStrLn $ "query from opts & args: " ++ (show $ queryFromOpts d $ reportopts_ opts)
|
putStrLn $ "query from opts & args: " ++ (show $ queryFromOpts d $ reportopts_ opts)
|
||||||
let
|
let
|
||||||
dbg s = if debug_ opts then trace s else id
|
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 = dbg "--help before command, showing general help" generalHelp
|
||||||
@ -151,7 +151,7 @@ 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)
|
||||||
when (debug_ opts) $ do
|
when (debug_ opts > 0) $ do
|
||||||
printf "external command selected: %s\n" cmd
|
printf "external command selected: %s\n" cmd
|
||||||
printf "external command arguments: %s\n" (show argsaftercmd)
|
printf "external command arguments: %s\n" (show argsaftercmd)
|
||||||
printf "running shell command: %s\n" (show shellcmd)
|
printf "running shell command: %s\n" (show shellcmd)
|
||||||
|
|||||||
@ -106,7 +106,6 @@ import Hledger
|
|||||||
import Hledger.Data.FormatStrings as Format
|
import Hledger.Data.FormatStrings as Format
|
||||||
import Hledger.Cli.Version
|
import Hledger.Cli.Version
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- 1. cmdargs mode and flag (option) definitions for the hledger CLI,
|
-- 1. cmdargs mode and flag (option) definitions for the hledger CLI,
|
||||||
-- can be reused by other packages as well.
|
-- can be reused by other packages as well.
|
||||||
@ -121,7 +120,7 @@ type RawOpts = [(String,String)]
|
|||||||
helpflags = [
|
helpflags = [
|
||||||
flagNone ["help","h","?"] (setboolopt "help") "Display general help or (with --help after COMMAND) command help."
|
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 ["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"
|
,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)
|
-- 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 {
|
data CliOpts = CliOpts {
|
||||||
rawopts_ :: RawOpts
|
rawopts_ :: RawOpts
|
||||||
,command_ :: String
|
,command_ :: String
|
||||||
,file_ :: Maybe FilePath
|
,file_ :: Maybe FilePath
|
||||||
,rules_file_ :: Maybe FilePath
|
,rules_file_ :: Maybe FilePath
|
||||||
,alias_ :: [String]
|
,alias_ :: [String]
|
||||||
,debug_ :: Bool
|
,debug_ :: Int -- ^ debug level, set by @--debug[=N]@. See also 'Hledger.Utils.debugLevel'.
|
||||||
,no_new_accounts_ :: Bool -- add
|
,no_new_accounts_ :: Bool -- add
|
||||||
,width_ :: Maybe String -- register
|
,width_ :: Maybe String -- register
|
||||||
,reportopts_ :: ReportOpts
|
,reportopts_ :: ReportOpts
|
||||||
@ -448,7 +447,7 @@ rawOptsToCliOpts rawopts = do
|
|||||||
,file_ = maybestringopt "file" rawopts
|
,file_ = maybestringopt "file" rawopts
|
||||||
,rules_file_ = maybestringopt "rules-file" rawopts
|
,rules_file_ = maybestringopt "rules-file" rawopts
|
||||||
,alias_ = map stripquotes $ listofstringopt "alias" rawopts
|
,alias_ = map stripquotes $ listofstringopt "alias" rawopts
|
||||||
,debug_ = boolopt "debug" rawopts
|
,debug_ = intopt "debug" rawopts
|
||||||
,no_new_accounts_ = boolopt "no-new-accounts" rawopts -- add
|
,no_new_accounts_ = boolopt "no-new-accounts" rawopts -- add
|
||||||
,width_ = maybestringopt "width" rawopts -- register
|
,width_ = maybestringopt "width" rawopts -- register
|
||||||
,reportopts_ = defreportopts {
|
,reportopts_ = defreportopts {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user