2021-01-12 21:55:00 +03:00
|
|
|
#!/usr/bin/env stack
|
2021-02-13 00:55:31 +03:00
|
|
|
-- stack runghc --verbosity info --package hledger --package string-qq
|
2021-01-12 22:07:29 +03:00
|
|
|
-- Run from inside the hledger source tree, or compile with compile.sh.
|
|
|
|
-- See hledger-check-fancyassertions.hs.
|
bin: switch scripts to "stack ghc" and "env -S" (#1453)
Using stack's script command meant that the scripts needed to be
compatible, and regularly tested, with a hledger release in stackage,
rather than the latest hledger source. This created hassles for
maintainers, contributors and sometimes for users.
To simplify things overall, we now require script users to check out
the hledger source tree and run the scripts (or, bin/compile.sh) from
there once so they compile themselves. Some notes on alternative
setups are included (in one of the scripts, and referenced by the
others). This ensures that users and our CI tests are building scripts
the same way.
Current stack does not allow a stack options line to be used with the
"stack ghc" command, unfortunately, so instead we are using env's -S
flag, which hopefully has sufficiently wide support by now, and
putting all arguments in the shebang line.
This method will probably require complete explicit --package options,
unlike "stack script", so more testing and tweaking is expected.
Probably we're going to end up with some long shebang lines.
This isn't pretty but seems like a possible way to keep things
manageable.
2021-01-12 04:42:13 +03:00
|
|
|
|
2020-08-15 19:56:53 +03:00
|
|
|
{-
|
|
|
|
Quick script that adds file/line number tags to print output.
|
|
|
|
cf https://www.reddit.com/r/plaintextaccounting/comments/ddzn8o/finding_corresponding_journal_files_from_hledger/
|
|
|
|
|
|
|
|
$ hledger print-location -f examples/sample.journal desc:eat
|
|
|
|
2008/06/03 * eat & shop
|
|
|
|
; location: /Users/simon/src/hledger/examples/sample.journal:30
|
|
|
|
expenses:food $1
|
|
|
|
expenses:supplies $1
|
|
|
|
assets:cash
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
import Data.String.QQ (s)
|
2022-03-10 04:13:28 +03:00
|
|
|
import qualified Data.Text as T
|
2020-08-15 19:56:53 +03:00
|
|
|
import Hledger.Cli
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
cmdmode = hledgerCommandMode
|
|
|
|
[s| print-location
|
|
|
|
Like print, but adds tags showing the file path and location of transactions.
|
2020-08-15 21:29:35 +03:00
|
|
|
_FLAGS
|
2020-08-15 19:56:53 +03:00
|
|
|
|]
|
|
|
|
[]
|
|
|
|
[generalflagsgroup1]
|
|
|
|
[]
|
|
|
|
([], Just $ argsFlag "[QUERY]")
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
opts <- getHledgerCliOpts cmdmode
|
|
|
|
withJournalDo opts $ \j ->
|
|
|
|
print' opts j{jtxns = map addLocationTag $ jtxns j}
|
|
|
|
|
|
|
|
addLocationTag :: Transaction -> Transaction
|
|
|
|
addLocationTag t = t{tcomment = tcomment t `commentAddTagNextLine` loctag}
|
|
|
|
where
|
2022-03-25 08:16:33 +03:00
|
|
|
loctag = ("location", T.pack . sourcePosPairPretty $ tsourcepos t)
|
2020-08-15 19:56:53 +03:00
|
|
|
|
2022-03-10 04:13:28 +03:00
|
|
|
-- Like showSourcePosPair in Hledger.Data.Transaction, but show just the starting line number.
|
|
|
|
showSourcePosPairLine :: (SourcePos, SourcePos) -> String
|
|
|
|
showSourcePosPairLine (SourcePos f line _, _) = f ++ ":" ++ show line
|