simplify "hours" behaviour, make it less different
This commit is contained in:
parent
44cb0674de
commit
ed0305fb96
40
Options.hs
40
Options.hs
@ -22,10 +22,11 @@ import Ledger.Dates
|
|||||||
progname = "hledger"
|
progname = "hledger"
|
||||||
timeprogname = "hours"
|
timeprogname = "hours"
|
||||||
|
|
||||||
usagehdr = printf (
|
usagehdr = (
|
||||||
"Usage: one of\n" ++
|
"Usage: hledger [OPTIONS] [COMMAND [PATTERNS]]\n" ++
|
||||||
" %s [OPTIONS] COMMAND [PATTERNS]\n" ++
|
" hours [OPTIONS] [COMMAND [PATTERNS]]\n" ++
|
||||||
" %s [OPTIONS] [PERIOD [COMMAND [PATTERNS]]]\n" ++
|
"\n" ++
|
||||||
|
"When invoked as \"hours\", uses your timelog and --period today as defaults.\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"COMMAND is one of (may be abbreviated):\n" ++
|
"COMMAND is one of (may be abbreviated):\n" ++
|
||||||
" balance - show account balances\n" ++
|
" balance - show account balances\n" ++
|
||||||
@ -46,7 +47,7 @@ usagehdr = printf (
|
|||||||
"Dates can be y/m/d or ledger-style smart dates like \"last month\".\n" ++
|
"Dates can be y/m/d or ledger-style smart dates like \"last month\".\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"Options:"
|
"Options:"
|
||||||
) progname timeprogname
|
)
|
||||||
|
|
||||||
|
|
||||||
usageftr = printf (
|
usageftr = printf (
|
||||||
@ -127,29 +128,20 @@ optValuesForConstructors fs opts = concatMap get opts
|
|||||||
where get o = if any (\f -> f v == o) fs then [v] else [] where v = value o
|
where get o = if any (\f -> f v == o) fs then [v] else [] where v = value o
|
||||||
|
|
||||||
-- | Parse the command-line arguments into options, command name, and
|
-- | Parse the command-line arguments into options, command name, and
|
||||||
-- command arguments. Any dates in the options are converted to full
|
-- command arguments. Any dates in the options are converted to explicit
|
||||||
-- YYYY/MM/DD format, while we are in the IO monad and can get the current
|
-- YYYY/MM/DD format based on the current time. If the program was invoked
|
||||||
-- time. Arguments are parsed differently if the program was invoked as
|
-- as \"hours\", the -f $TIMELOG -p today options are assumed as a default.
|
||||||
-- \"hours\".
|
|
||||||
parseArguments :: IO ([Opt], String, [String])
|
parseArguments :: IO ([Opt], String, [String])
|
||||||
parseArguments = do
|
parseArguments = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
istimequery <- usingTimeProgramName
|
|
||||||
let (os,as,es) = getOpt Permute options args
|
let (os,as,es) = getOpt Permute options args
|
||||||
os' <- fixOptDates os
|
istimequery <- usingTimeProgramName
|
||||||
case istimequery of
|
let os' = if istimequery then (Period "today"):os else os
|
||||||
False ->
|
os'' <- fixOptDates os'
|
||||||
case (os,as,es) of
|
case (as,es) of
|
||||||
(opts,cmd:args,[]) -> return (os',cmd,args)
|
(cmd:args,[]) -> return (os'',cmd,args)
|
||||||
(opts,[],[]) -> return (os',"",[])
|
([],[]) -> return (os'',"",[])
|
||||||
(opts,_,errs) -> ioError (userError (concat errs ++ usage))
|
(_,errs) -> ioError (userError (concat errs ++ usage))
|
||||||
True ->
|
|
||||||
case (os,as,es) of
|
|
||||||
(opts,p:cmd:args,[]) -> return (os' ++ [Period p],cmd,args)
|
|
||||||
(opts,p:args,[]) -> return ([Period p,SubTotal] ++ os',"balance",args)
|
|
||||||
(opts,[],[]) -> return ([Period "today",SubTotal] ++ os',"balance",[])
|
|
||||||
(opts,_,errs) -> ioError (userError (concat errs ++ usage))
|
|
||||||
|
|
||||||
|
|
||||||
-- | Convert any fuzzy dates within these option values to explicit ones,
|
-- | Convert any fuzzy dates within these option values to explicit ones,
|
||||||
-- based on today's date.
|
-- based on today's date.
|
||||||
|
|||||||
12
README
12
README
@ -59,15 +59,15 @@ results. Here are some commands to try::
|
|||||||
|
|
||||||
Time reporting
|
Time reporting
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
hledger will also read timeclock.el-format timelog entries. As a
|
hledger will also read timeclock.el-format timelog entries. As a
|
||||||
convenience, if you invoke the hledger executable via a link or copy named
|
convenience, if you invoke hledger via a link or copy named "hours", it
|
||||||
"hours", it looks for your timelog file (~/.timelog, or the file specified
|
uses your timelog file (~/.timelog or $TIMELOG) and --period today as
|
||||||
by $TIMELOG or -f), and parses arguments slightly differently::
|
defaults.
|
||||||
|
|
||||||
hours [OPTIONS] [PERIOD [COMMAND [PATTERNS]]]
|
hours [OPTIONS] [COMMAND [PATTERNS]]
|
||||||
|
|
||||||
where PERIOD is a ledger-style period expression, defaulting to "today",
|
Timelog entries look like this::
|
||||||
and COMMAND is one of the commands above. Timelog entries look like this::
|
|
||||||
|
|
||||||
i 2009/03/31 22:21:45 some:project
|
i 2009/03/31 22:21:45 some:project
|
||||||
o 2009/04/01 02:00:34
|
o 2009/04/01 02:00:34
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user