From db7783b16d8c048148381587b46b136e9e865494 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 14 Aug 2025 12:17:18 +0100 Subject: [PATCH] dev: cleanups --- hledger-lib/Hledger/Read.hs | 6 +++--- hledger-lib/Hledger/Read/CsvReader.hs | 8 +++----- hledger-lib/Hledger/Utils/IO.hs | 3 ++- hledger/Hledger/Cli/Commands/Import.hs | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index 6a68560ac..c8b52a365 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -332,9 +332,9 @@ readJournalFiles iopts@InputOpts{strict_, new_, new_save_} prefixedfiles = do when (new_ && new_save_) $ liftIO $ saveLatestDatesForFiles latestdatesforfiles return j --- The implementation of readJournalFiles, but with --new, --- also returns the latest transaction date(s) read in each file. --- Used by the import command, to save those at the end. +-- The implementation of readJournalFiles. +-- With --new, it also returns the latest transaction date(s) read in each file +-- (used by the import command). readJournalFilesAndLatestDates :: InputOpts -> [PrefixedFilePath] -> ExceptT String IO (Journal, [LatestDatesForFile]) readJournalFilesAndLatestDates iopts pfs = do (js, lastdates) <- unzip <$> mapM (readJournalFileAndLatestDates iopts) pfs diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index 747c92138..d5e41591a 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -54,10 +54,9 @@ reader sep = Reader -- but not good if it was loaded by a possibly long chain of include directives. } --- | Parse and post-process a "Journal" from CSV data, or give an error. --- This currently ignores the provided data, and reads it from the file path instead. --- This file path is normally the CSV(/SSV/TSV) data file, and a corresponding rules file is inferred. --- But it can also be the rules file, in which case the corresponding data file is inferred. +-- | Parse and post-process a "Journal" from a CSV(/SSV/TSV/*SV) data file, or give an error. +-- This currently ignores the provided input file handle, and reads from the data file itself, +-- inferring a corresponding rules file to help convert it. -- This does not check balance assertions. parse :: SepFormat -> InputOpts -> FilePath -> Handle -> ExceptT String IO Journal parse sep iopts f h = do @@ -76,4 +75,3 @@ parse sep iopts f h = do tests_CsvReader = testGroup "CsvReader" [ ] - diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index fea742dce..a8a5438d6 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -221,7 +221,8 @@ ansiFormatError = (<> sgrresetall) . ((sgrbrightred <> sgrbold) <>) -- | Show a message, with "Warning:" label, on stderr before returning the given value. -- Also do some ANSI styling of the first line when allowed (using unsafe IO). -- Currently we use this very sparingly in hledger; we prefer to either quietly work, --- or loudly raise an error. (Varying output can make scripting harder.) +-- or loudly raise an error. Varying output can make scripting harder, +-- but on stderr, it shouldn't cause much hassle. warn :: String -> a -> a warn msg = trace msg' where diff --git a/hledger/Hledger/Cli/Commands/Import.hs b/hledger/Hledger/Cli/Commands/Import.hs index f8c7d9a76..c754085f5 100644 --- a/hledger/Hledger/Cli/Commands/Import.hs +++ b/hledger/Hledger/Cli/Commands/Import.hs @@ -12,12 +12,12 @@ where import Control.Monad import Data.List import qualified Data.Text.IO as T +import System.Console.CmdArgs.Explicit +import Text.Printf + import Hledger import Hledger.Cli.CliOptions import Hledger.Cli.Commands.Add (journalAddTransaction) --- import Hledger.Cli.Commands.Print (print') -import System.Console.CmdArgs.Explicit -import Text.Printf importmode = hledgerCommandMode $(embedFileRelative "Hledger/Cli/Commands/Import.txt")