From d352bbedd24da4e61db60153e16d5ddb3f53edf4 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 4 Dec 2014 12:41:47 -0800 Subject: [PATCH] cli: with a repeated flag, the last takes precedence This is helpful eg for customising your reporting command aliases on the fly. --- doc/manual.md | 12 ++++++++---- hledger-lib/Hledger/Data/RawOptions.hs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/manual.md b/doc/manual.md index 88d3fbb3e..4cce3711b 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -46,10 +46,14 @@ in your home directory. You can specify a different file with the `-f` option or `LEDGER_FILE` environment variable, or standard input with `-f-`. Options are similar across most commands, with some variations; use -`hledger COMMAND --help` for details. Most options must appear -somewhere after COMMAND, not before it. These input and help-related -options can appear anywhere: `-f`, `--rules-file`, `--alias`, -`--ignore-assertions`, `--help`, `--debug`, `--version`. +`hledger COMMAND --help` for details. + +Most options must appear after COMMAND, not before it; but the +following general options can appear anywhere: `-f`, `--rules-file`, +`--alias`, `--ignore-assertions`, `--help`, `--debug`, `--version`. + +If an option is repeated, the last one takes precedence. Eg `-p jan -p +feb` is equivalent to `-p feb`. Arguments are also command-specific, but usually they form a [query](#queries) which selects a subset of the journal, eg transactions diff --git a/hledger-lib/Hledger/Data/RawOptions.hs b/hledger-lib/Hledger/Data/RawOptions.hs index 33b4c77fc..0d9f3b5a0 100644 --- a/hledger-lib/Hledger/Data/RawOptions.hs +++ b/hledger-lib/Hledger/Data/RawOptions.hs @@ -45,7 +45,7 @@ boolopt :: String -> RawOpts -> Bool boolopt = inRawOpts maybestringopt :: String -> RawOpts -> Maybe String -maybestringopt name = maybe Nothing (Just . stripquotes) . lookup name +maybestringopt name = maybe Nothing (Just . stripquotes) . lookup name . reverse stringopt :: String -> RawOpts -> String stringopt name = fromMaybe "" . maybestringopt name