mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
cli, ui, web: make -NUM a shortcut for --depth NUM
This commit is contained in:
parent
4be996ba89
commit
fead7c5138
@ -141,8 +141,8 @@ m4_define({{_reportingoptions_}}, {{
|
||||
`-R --real`
|
||||
: include only non-virtual postings
|
||||
|
||||
`--depth=N`
|
||||
: hide accounts/postings deeper than N
|
||||
`-NUM --depth=NUM`
|
||||
: hide/aggregate accounts or postings more than NUM levels deep
|
||||
|
||||
`-E --empty`
|
||||
: show items with zero amount, normally hidden
|
||||
|
@ -10,6 +10,7 @@ import Data.Default
|
||||
import Data.Functor.Compat ((<$>))
|
||||
#endif
|
||||
import Data.List (intercalate)
|
||||
import System.Environment
|
||||
|
||||
import Hledger.Cli hiding (progname,version,prognameandversion)
|
||||
import Hledger.UI.Theme (themeNames)
|
||||
@ -94,6 +95,12 @@ checkUIOpts opts =
|
||||
Just t | not $ elem t themeNames -> Left $ "invalid theme name: "++t
|
||||
_ -> Right ()
|
||||
|
||||
-- XXX some refactoring seems due
|
||||
getHledgerUIOpts :: IO UIOpts
|
||||
getHledgerUIOpts = processArgs uimode >>= return . decodeRawOpts >>= rawOptsToUIOpts
|
||||
--getHledgerUIOpts = processArgs uimode >>= return . decodeRawOpts >>= rawOptsToUIOpts
|
||||
getHledgerUIOpts = do
|
||||
args <- getArgs
|
||||
let args' = replaceNumericFlags args
|
||||
let cmdargopts = either usageError id $ process uimode args'
|
||||
rawOptsToUIOpts $ decodeRawOpts cmdargopts
|
||||
|
||||
|
@ -7,6 +7,7 @@ import Data.Default
|
||||
import Data.Functor.Compat ((<$>))
|
||||
#endif
|
||||
import Data.Maybe
|
||||
import System.Environment
|
||||
|
||||
import Hledger.Cli hiding (progname,version,prognameandversion)
|
||||
import Settings
|
||||
@ -92,5 +93,10 @@ checkWebOpts wopts =
|
||||
else Right ()
|
||||
|
||||
getHledgerWebOpts :: IO WebOpts
|
||||
getHledgerWebOpts = processArgs webmode >>= return . decodeRawOpts >>= rawOptsToWebOpts
|
||||
--getHledgerWebOpts = processArgs webmode >>= return . decodeRawOpts >>= rawOptsToWebOpts
|
||||
getHledgerWebOpts = do
|
||||
args <- getArgs
|
||||
let args' = replaceNumericFlags args
|
||||
let cmdargopts = either usageError id $ process webmode args'
|
||||
rawOptsToWebOpts $ decodeRawOpts cmdargopts
|
||||
|
||||
|
@ -51,6 +51,7 @@ module Hledger.Cli.CliOptions (
|
||||
outputFormatFromOpts,
|
||||
defaultWidth,
|
||||
widthFromOpts,
|
||||
replaceNumericFlags,
|
||||
-- | For register:
|
||||
registerWidthsFromOpts,
|
||||
maybeAccountNameDrop,
|
||||
@ -75,6 +76,7 @@ import Prelude ()
|
||||
import Prelude.Compat
|
||||
import qualified Control.Exception as C
|
||||
import Control.Monad (when)
|
||||
import Data.Char
|
||||
import Data.Default
|
||||
#if !MIN_VERSION_base(4,8,0)
|
||||
import Data.Functor.Compat ((<$>))
|
||||
@ -149,7 +151,7 @@ reportflags = [
|
||||
,flagNone ["pending","P"] (setboolopt "pending") "include only pending postings/txns"
|
||||
,flagNone ["cleared","C"] (setboolopt "cleared") "include only cleared postings/txns"
|
||||
,flagNone ["real","R"] (setboolopt "real") "include only non-virtual postings"
|
||||
,flagReq ["depth"] (\s opts -> Right $ setopt "depth" s opts) "N" "hide accounts/postings deeper than N"
|
||||
,flagReq ["depth"] (\s opts -> Right $ setopt "depth" s opts) "NUM" "(or -NUM): hide accounts/postings deeper than this"
|
||||
,flagNone ["empty","E"] (setboolopt "empty") "show items with zero amount, normally hidden"
|
||||
,flagNone ["cost","B"] (setboolopt "cost") "convert amounts to their cost at transaction time (using the transaction price, if any)"
|
||||
,flagNone ["value","V"] (setboolopt "value") "convert amounts to their market value on the report end date (using the most recent applicable market price, if any)"
|
||||
@ -377,6 +379,14 @@ decodeRawOpts = map (\(name',val) -> (name', fromSystemString val))
|
||||
defaultWidth :: Int
|
||||
defaultWidth = 80
|
||||
|
||||
-- | Replace any numeric flags (eg -2) with their long form (--depth 2),
|
||||
-- as I'm guessing cmdargs doesn't support this directly.
|
||||
replaceNumericFlags :: [String] -> [String]
|
||||
replaceNumericFlags = map replace
|
||||
where
|
||||
replace ('-':ds) | not (null ds) && all isDigit ds = "--depth="++ds
|
||||
replace s = s
|
||||
|
||||
-- | Parse raw option string values to the desired final data types.
|
||||
-- Any relative smart dates will be converted to fixed dates based on
|
||||
-- today's date. Parsing failures will raise an error.
|
||||
|
@ -108,7 +108,7 @@ main = do
|
||||
-- some preliminary (imperfect) argument parsing to supplement cmdargs
|
||||
args <- getArgs
|
||||
let
|
||||
args' = moveFlagsAfterCommand args
|
||||
args' = moveFlagsAfterCommand $ replaceNumericFlags args
|
||||
isFlag = ("-" `isPrefixOf`)
|
||||
isNonEmptyNonFlag s = not (isFlag s) && not (null s)
|
||||
rawcmd = headDef "" $ takeWhile isNonEmptyNonFlag args'
|
||||
@ -201,7 +201,7 @@ main = do
|
||||
argsToCliOpts :: [String] -> [String] -> IO CliOpts
|
||||
argsToCliOpts args addons = do
|
||||
let
|
||||
args' = moveFlagsAfterCommand args
|
||||
args' = moveFlagsAfterCommand $ replaceNumericFlags args
|
||||
cmdargsopts = either usageError id $ process (mainmode addons) args'
|
||||
cmdargsopts' = decodeRawOpts cmdargsopts
|
||||
rawOptsToCliOpts cmdargsopts'
|
||||
|
@ -258,9 +258,11 @@ Group postings from start of wednesday to end of next tuesday (N is start date a
|
||||
|
||||
## Depth limiting
|
||||
|
||||
With the `--depth N` option, commands like [account](#account), [balance](#balance)
|
||||
With the `--depth N` option (short form: `-N`), commands like [account](#account), [balance](#balance)
|
||||
and [register](#register) will show only the uppermost accounts in the account
|
||||
tree, down to level N. Use this when you want a summary with less detail.
|
||||
This flag has the same effect as a `depth:` query argument
|
||||
(so `-2`, `--depth=2` or `depth:2` are basically equivalent).
|
||||
|
||||
## Pivoting
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user