imp: cli: rename --rules-file to --rules; tweak options help

For brevity, and consistency with --conf.
--rules-file remains supported, as a hidden option.

hledger's main mode now supports the hidden legacy flags,
as the command modes do.
This commit is contained in:
Simon Michael 2024-06-25 07:08:14 +01:00
parent 5739bff249
commit 40620666f8
11 changed files with 17 additions and 17 deletions

View File

@ -13,7 +13,7 @@
- Import new transactions from all CSV files, using the same rules for all: - Import new transactions from all CSV files, using the same rules for all:
`hledger import --rules-file {{common.rules}} *.csv` `hledger import --rules {{common.rules}} *.csv`
- Show conversion errors or results while editing `bank.csv.rules`: - Show conversion errors or results while editing `bank.csv.rules`:

View File

@ -209,7 +209,7 @@ rawOptsToInputOpts day rawopts =
in definputopts{ in definputopts{
-- files_ = listofstringopt "file" rawopts -- files_ = listofstringopt "file" rawopts
mformat_ = Nothing mformat_ = Nothing
,mrules_file_ = maybestringopt "rules-file" rawopts ,mrules_file_ = maybestringopt "rules" rawopts
,aliases_ = listofstringopt "alias" rawopts ,aliases_ = listofstringopt "alias" rawopts
,anon_ = boolopt "obfuscate" rawopts ,anon_ = boolopt "obfuscate" rawopts
,new_ = boolopt "new" rawopts ,new_ = boolopt "new" rawopts

View File

@ -112,7 +112,7 @@ getDownloadDir = do
-- file's directory. When a glob pattern matches multiple files, the alphabetically -- file's directory. When a glob pattern matches multiple files, the alphabetically
-- last is used. (Eg in case of multiple numbered downloads, the highest-numbered -- last is used. (Eg in case of multiple numbered downloads, the highest-numbered
-- will be used.) -- will be used.)
-- The provided text, or a --rules-file option, are ignored by this reader. -- The provided text, or a --rules option, are ignored by this reader.
-- Balance assertions are not checked. -- Balance assertions are not checked.
parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal
parse iopts f _ = do parse iopts f _ = do
@ -883,7 +883,7 @@ _CSV_READING__________________________________________ = undefined
-- 4. Return the transactions as a Journal. -- 4. Return the transactions as a Journal.
-- --
readJournalFromCsv :: Maybe (Either CsvRules FilePath) -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO Journal readJournalFromCsv :: Maybe (Either CsvRules FilePath) -> FilePath -> Text -> Maybe SepFormat -> ExceptT String IO Journal
readJournalFromCsv Nothing "-" _ _ = throwError "please use --rules-file when reading CSV from stdin" readJournalFromCsv Nothing "-" _ _ = throwError "please use --rules when reading CSV from stdin"
readJournalFromCsv merulesfile csvfile csvtext sep = do readJournalFromCsv merulesfile csvfile csvtext sep = do
-- for now, correctness is the priority here, efficiency not so much -- for now, correctness is the priority here, efficiency not so much

View File

@ -47,7 +47,6 @@ prognameandversion =
uiflags = [ uiflags = [
-- flagNone ["debug-ui"] (setboolopt "rules-file") "run with no terminal output, showing console"
flagNone ["watch","w"] (setboolopt "watch") "watch for data and date changes and reload automatically" flagNone ["watch","w"] (setboolopt "watch") "watch for data and date changes and reload automatically"
,flagReq ["theme"] (\s opts -> Right $ setopt "theme" s opts) "THEME" ("use this custom display theme ("++intercalate ", " themeNames++")") ,flagReq ["theme"] (\s opts -> Right $ setopt "theme" s opts) "THEME" ("use this custom display theme ("++intercalate ", " themeNames++")")
,flagNone ["cash"] (setboolopt "cash") "start in the cash accounts screen" ,flagNone ["cash"] (setboolopt "cash") "start in the cash accounts screen"

View File

@ -141,7 +141,8 @@ mainmode addons = defMode {
] ]
-- flags handled but not shown in the help: -- flags handled but not shown in the help:
,groupHidden = ,groupHidden =
[detailedversionflag] detailedversionflag :
hiddenflags
-- ++ inputflags -- included here so they'll not raise a confusing error if present with no COMMAND -- ++ inputflags -- included here so they'll not raise a confusing error if present with no COMMAND
} }
,modeHelpSuffix = [] ,modeHelpSuffix = []

View File

@ -143,7 +143,7 @@ prognameandversion =
-- common cmdargs flags -- common cmdargs flags
-- keep synced with flag docs in doc/common.m4 -- keep synced with flag docs in doc/common.m4
-- | Common input-related flags: --file, --rules-file, --alias... -- | Common input-related flags: --file, --rules, --conf, --alias...
inputflags :: [Flag RawOpts] inputflags :: [Flag RawOpts]
inputflags = [ inputflags = [
flagReq ["file","f"] (\s opts -> Right $ setopt "file" s opts) "[FMT:]FILE" "Read data from FILE, or from stdin if FILE is -, inferring format from extension or a FMT: prefix. Can be specified more than once. If not specified, reads from $LEDGER_FILE or $HOME/.hledger.journal." flagReq ["file","f"] (\s opts -> Right $ setopt "file" s opts) "[FMT:]FILE" "Read data from FILE, or from stdin if FILE is -, inferring format from extension or a FMT: prefix. Can be specified more than once. If not specified, reads from $LEDGER_FILE or $HOME/.hledger.journal."
@ -275,6 +275,7 @@ hiddenflags = [
,flagNone ["pretty-tables"] (setopt "pretty" "always") "legacy flag that was renamed" ,flagNone ["pretty-tables"] (setopt "pretty" "always") "legacy flag that was renamed"
,flagNone ["anon"] (setboolopt "anon") "deprecated, renamed to --obfuscate" -- #2133, handled by anonymiseByOpts ,flagNone ["anon"] (setboolopt "anon") "deprecated, renamed to --obfuscate" -- #2133, handled by anonymiseByOpts
,flagNone ["obfuscate"] (setboolopt "obfuscate") "slightly obfuscate hledger's output. Warning, does not give privacy. Formerly --anon." -- #2133, handled by maybeObfuscate ,flagNone ["obfuscate"] (setboolopt "obfuscate") "slightly obfuscate hledger's output. Warning, does not give privacy. Formerly --anon." -- #2133, handled by maybeObfuscate
,flagReq ["rules-file"] (\s opts -> Right $ setopt "rules" s opts) "RULESFILE" "was renamed to --rules"
] ]
-- | Common output-related flags: --output-file, --output-format... -- | Common output-related flags: --output-file, --output-format...

View File

@ -2908,7 +2908,7 @@ attributes.
By default, hledger expects this rules file to be named like the CSV file, By default, hledger expects this rules file to be named like the CSV file,
with an extra `.rules` extension added, in the same directory. with an extra `.rules` extension added, in the same directory.
Eg when asked to read `foo/FILE.csv`, hledger looks for `foo/FILE.csv.rules`. Eg when asked to read `foo/FILE.csv`, hledger looks for `foo/FILE.csv.rules`.
You can specify a different rules file with the `--rules-file` option. You can specify a different rules file with the `--rules` option.
At minimum, the rules file must identify the date and amount fields, At minimum, the rules file must identify the date and amount fields,
and often it also specifies the date format and how many header lines and often it also specifies the date format and how many header lines
@ -3634,9 +3634,8 @@ $ cat foo.dat | hledger -f ssv:- print
### Reading multiple CSV files ### Reading multiple CSV files
If you use multiple `-f` options to read multiple CSV files at once, If you use multiple `-f` options to read multiple CSV files at once,
hledger will look for a correspondingly-named rules file for each CSV hledger will look for a correspondingly-named rules file for each CSV file.
file. But if you use the `--rules-file` option, that rules file will But if you specify a rules file with `--rules`, that rules file will be used for all the CSV files.
be used for all the CSV files.
### Reading files specified by rule ### Reading files specified by rule

View File

@ -48,8 +48,8 @@
# - an unrecognised command shows an error and gives non-zero exit status # - an unrecognised command shows an error and gives non-zero exit status
# #
# - usually the command must come first, followed by options and arguments in any order # - usually the command must come first, followed by options and arguments in any order
# - a few options may also go before the command: -f, --rules-file, --alias, --help, --version, --debug. # - a few options may also go before the command: -f, --rules, --alias, --help, --version, --debug.
# - option flags may be written in full or as a unique prefix, eg --rules for --rules-file # - option flags may be written in full or as a unique prefix
# - if the command is external, options and arguments after the command are handled by that executable, not hledger # - if the command is external, options and arguments after the command are handled by that executable, not hledger
# #
# - the --help flag has highest priority # - the --help flag has highest priority

View File

@ -523,7 +523,7 @@ expecting '!', '*', or end of input
### csvstdinrules ### csvstdinrules
``` ```
hledger: Error: please use --rules-file when reading CSV from stdin hledger: Error: please use --rules when reading CSV from stdin
``` ```
@ -535,6 +535,6 @@ hledger: Error: CSV record ["b"] has less than two fields
### csvstdinrules ### csvstdinrules
``` ```
hledger: Error: please use --rules-file when reading CSV from stdin hledger: Error: please use --rules when reading CSV from stdin
``` ```

View File

@ -1,4 +1,4 @@
$$$ sh csvstdinrules.sh $$$ sh csvstdinrules.sh
>>>2 /hledger: Error: please use --rules-file when reading CSV from stdin >>>2 /hledger: Error: please use --rules when reading CSV from stdin
/ /
>>>= 1 >>>= 1

View File

@ -1,6 +1,6 @@
# Various match group interpolation tests. See the comments # Various match group interpolation tests. See the comments
# in match.rules for specifics. # in match.rules for specifics.
$ hledger -f a.j import --rules-file match.rules --dry-run match.csv $ hledger -f a.j import --rules match.rules --dry-run match.csv
; would import 1 new transactions from match.csv: ; would import 1 new transactions from match.csv:
2022-12-15 Zettle_*Robert W. Bell 2022-12-15 Zettle_*Robert W. Bell