fix: bin: Get hledger-print-location working.

This commit is contained in:
Stephen Morgan 2022-03-10 12:13:28 +11:00 committed by Simon Michael
parent 19ed6d3f00
commit 852ba7b100

View File

@ -19,8 +19,7 @@ $ hledger print-location -f examples/sample.journal desc:eat
{-# LANGUAGE QuasiQuotes #-}
import Data.String.QQ (s)
import Data.Text (pack)
import Text.Printf
import qualified Data.Text as T
import Hledger.Cli
------------------------------------------------------------------------------
@ -44,9 +43,8 @@ main = do
addLocationTag :: Transaction -> Transaction
addLocationTag t = t{tcomment = tcomment t `commentAddTagNextLine` loctag}
where
loctag = ("location", pack $ showGenericSourcePosLine $ tsourcepos t)
loctag = ("location", T.pack . showSourcePosPair $ tsourcepos t)
-- Like showGenericSourcePos in Hledger.Data.Transaction, but show just the starting line number.
showGenericSourcePosLine :: GenericSourcePos -> String
showGenericSourcePosLine (GenericSourcePos f line _) = printf "%s:%d" f line
showGenericSourcePosLine (JournalSourcePos f (startline, _)) = printf "%s:%d" f startline
-- Like showSourcePosPair in Hledger.Data.Transaction, but show just the starting line number.
showSourcePosPairLine :: (SourcePos, SourcePos) -> String
showSourcePosPairLine (SourcePos f line _, _) = f ++ ":" ++ show line