From c60ec907560d537d2d2ebe40aaeb11c445e0720a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 24 Aug 2025 09:25:53 +0100 Subject: [PATCH] dev:import: improve buggy detection of import command --- hledger-lib/Hledger/Read/RulesReader.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Read/RulesReader.hs b/hledger-lib/Hledger/Read/RulesReader.hs index 56a4336e1..dfe86154e 100644 --- a/hledger-lib/Hledger/Read/RulesReader.hs +++ b/hledger-lib/Hledger/Read/RulesReader.hs @@ -157,8 +157,10 @@ parse iopts rulesfile h = do let -- XXX How can we know when the command is import, and if it's a dry run ? In a hacky way, currently. args = progArgs - cmd = headDef "" $ dropWhile ((=="-").take 1) args - cmdisimport = dbg7 "cmdisimport" $ cmd `elem` ["import", "imp"] + -- XXX Difficult to identify the command name reliably here, + -- Cli.hs's moveFlagsAfterCommand would help but is not importable here. + -- Just look for import or imp appearing anywhere in the arguments. + cmdisimport = dbg7 "cmdisimport" $ any (`elem` args) ["import", "imp"] dryrun = dbg7 "dryrun" $ any (`elem` args) ["--dry-run", "--dry"] importing = dbg7 "importing" $ cmdisimport && not dryrun archive = dbg7 "archive" $ isJust (getDirective "archive" rules)