From 7ac154e0b85733d8451f198459b8e17915dd6f8a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 14 Oct 2024 08:26:25 -1000 Subject: [PATCH] dev: cli: fix recent command parsing breakage; more tests --- hledger/Hledger/Cli.hs | 2 +- hledger/test/cli/cli.test | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index fa436b8c0..6669d261d 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -268,7 +268,7 @@ main = withGhcDebug' $ do -- If no command argument was provided, or if cmdargs fails because -- the command line contains a bad flag or wrongly present/missing flag value, -- cmdname will be "". - args = confallgenargs <> cliargswithcmdfirstwithoutclispecific + args = [confcmdarg | not $ null confcmdarg] <> cliargswithcmdfirstwithoutclispecific cmdname = stringopt "command" $ cmdargsParse "for command name" (mainmode addons) args badcmdprovided = null cmdname && not nocmdprovided isaddoncmd = not (null cmdname) && cmdname `elem` addons diff --git a/hledger/test/cli/cli.test b/hledger/test/cli/cli.test index e7afc625b..6683268de 100644 --- a/hledger/test/cli/cli.test +++ b/hledger/test/cli/cli.test @@ -154,3 +154,13 @@ $ hledger -f /dev/null --no-conf --conf nosuchfile check $ hledger --debug -f /dev/null --conf /dev/null --no-conf >/dev/null >2 /ignoring config files/ +# ** 25. Having general options in a conf file doesn't break cli command parsing. +$ echo '--pretty' >$$.conf; hledger -f /dev/null --conf $$.conf files; rm -f $$.conf +/dev/null + +# ** 26. An initial non-flag general argument in a conf file is used as the command. +$ echo 'files' >$$.conf; hledger stats -f /dev/null --conf $$.conf; rm -f $$.conf + +# ** 27. A non-flag general argument that's not first in the conf file is note used as the command. +$ echo '--pretty files' >$$.conf; hledger stats -f /dev/null --conf $$.conf; rm -f $$.conf +> /Runtime stats/