From 6f3c4c9bf091d0c1eaf596d47c19b33f1f6d32a6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 12 Jul 2024 15:41:53 +0100 Subject: [PATCH] fix: cli: accept --conf with no command --- hledger/Hledger/Cli.hs | 8 ++++---- hledger/Hledger/Cli/CliOptions.hs | 13 ++++++++----- hledger/test/cli/cli.test | 14 +++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 3803af7b9..121e44c22 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -140,10 +140,10 @@ mainmode addons = defMode { ,modeGroupFlags = Group { -- flags in named groups: (keep synced with Hledger.Cli.CliOptions.highlightHelp) groupNamed = cligeneralflagsgroups1 - -- flags in the unnamed group, shown last: - ,groupUnnamed = confflags -- keep synced with dropUnsupportedOpts - -- flags handled but not shown in the help: - ,groupHidden = hiddenflags + -- flags in the unnamed group, shown last: (keep synced with dropUnsupportedOpts) + ,groupUnnamed = confflags + -- other flags handled but not shown in help: + ,groupHidden = hiddenflagsformainmode } ,modeHelpSuffix = [] -- "Examples:" : diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 023aa24b4..7ba115893 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -27,6 +27,7 @@ module Hledger.Cli.CliOptions ( flattreeflags, confflags, hiddenflags, + hiddenflagsformainmode, -- outputflags, outputFormatFlag, outputFileFlag, @@ -267,10 +268,9 @@ confflags = [ ,flagNone ["no-conf","n"] (setboolopt "no-conf") "ignore any config file" ] --- | Common flags that are accepted but not shown in --help, --- such as --effective, --aux-date. -hiddenflags :: [Flag RawOpts] -hiddenflags = [ +-- | Common legacy flags that are accepted but not shown in --help. +hiddenflagsformainmode :: [Flag RawOpts] +hiddenflagsformainmode = [ flagNone ["effective","aux-date"] (setboolopt "date2") "Ledger-compatible aliases for --date2" ,flagNone ["infer-value"] (setboolopt "infer-market-prices") "legacy flag that was renamed" ,flagNone ["pretty-tables"] (setopt "pretty" "always") "legacy flag that was renamed" @@ -278,7 +278,10 @@ hiddenflags = [ ,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" ] - ++ confflags -- repeated here so subcommands/addons won't error when parsing them + +-- Subcommands/addons add the conf flags, so they won't error if those are present. +hiddenflags :: [Flag RawOpts] +hiddenflags = hiddenflagsformainmode ++ confflags -- | Common output-related flags: --output-file, --output-format... diff --git a/hledger/test/cli/cli.test b/hledger/test/cli/cli.test index 29df58997..8d20afbb8 100644 --- a/hledger/test/cli/cli.test +++ b/hledger/test/cli/cli.test @@ -114,25 +114,29 @@ $ hledger --no-conf check -f/dev/null # ** 15. --conf CONFFILE works with builtin commands. $ hledger --conf /dev/null check -f/dev/null -# ** 16. When moving options written before the command name: +# ** 16. --conf works with no command. +$ hledger --conf /dev/null +> /Commands/ + +# ** 17. When moving options written before the command name: # if the flag name is used in general options and also one or more commands, # the general option's arity determines whether a value is expected. # Here -p is a help command flag taking no value, but also a general option requiring a value, # so the value ("today") is detected. $ hledger -p today check -f/dev/null -# ** 17. The specially-handled --debug option is also moved properly, with no value: +# ** 18. The specially-handled --debug option is also moved properly, with no value: $ hledger --debug check -f/dev/null >2 // -# ** 18. a joined value: +# ** 19. a joined value: $ hledger --debug=1 check -f/dev/null >2 // -# ** 19. or a separate value: +# ** 20. or a separate value: $ hledger --debug 1 check -f/dev/null >2 // -# ** 20. A short flag with joined value, or multiple valueless short flags joined together, are moved properly. +# ** 21. A short flag with joined value, or multiple valueless short flags joined together, are moved properly. $ hledger -f/dev/null -BI check >2 //