Skip to content

Commit e8e508b

Browse files
committed
Use the LEDGER_FILE env var (if set) when generating reports.
Default to the all-years.journal if LEDGER_FILE is not set.
1 parent 7384ed8 commit e8e508b

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

ChangeLog.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ or the current directory, and generate only the relevant include files.
88
This is a behavioural change and (for now) it needs to be enabled with the --enable-future-rundir switch.
99
This will become the default behaviour in 0.14.x, at which time the switch will be removed.
1010

11+
Reports:
12+
Use the LEDGER_FILE env var (if set) when generating reports.
13+
Default to the top-level all-years.journal if not set.
14+
15+
Build with Stackage Nightly 2020-03-10 (ghc-8.8.3)
16+
1117
## 0.13.1
1218

1319
- Automatically add [include lines for yearly price files](https://github.com/apauley/hledger-flow/#price-files) if they are present on disk.

src/Hledger/Flow/Reports.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Hledger.Flow.RuntimeOptions
1010
import Hledger.Flow.Common
1111
import Control.Concurrent.STM
1212
import Data.Either
13+
import Data.Maybe
1314

1415
import qualified Data.Text as T
1516
import qualified Hledger.Flow.Types as FlowTypes
@@ -44,10 +45,16 @@ generateReports' opts ch = do
4445
<> "https://github.com/apauley/hledger-flow/issues\n"
4546
channelOutLn ch wipMsg
4647
owners <- single $ shellToList $ listOwners opts
47-
let aggregateJournal = journalFile opts []
48+
ledgerEnvValue <- need "LEDGER_FILE" :: IO (Maybe Text)
49+
let hledgerJournal = fromMaybe (baseDir opts </> allYearsFileName) $ fmap fromText ledgerEnvValue
50+
hledgerJournalExists <- testfile hledgerJournal
51+
_ <- if not hledgerJournalExists then die $ format ("Unable to find journal file: "%fp%"\nIs your LEDGER_FILE environment variable set correctly?") hledgerJournal else return ()
52+
let journalWithYears = journalFile opts []
4853
let aggregateReportDir = outputReportDir opts ["all"]
49-
aggregateYears <- includeYears ch aggregateJournal
50-
let aggregateParams = ReportParams aggregateJournal aggregateYears aggregateReportDir
54+
aggregateYears <- includeYears ch journalWithYears
55+
let aggregateParams = ReportParams { ledgerFile = hledgerJournal
56+
, reportYears = aggregateYears
57+
, outputDir = aggregateReportDir}
5158
let aggregateOnlyReports = reportActions opts ch [transferBalance] aggregateParams
5259
ownerParams <- ownerParameters opts ch owners
5360
let ownerWithAggregateParams = (if length owners > 1 then [aggregateParams] else []) ++ ownerParams

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# resolver: ./custom-snapshot.yaml
2020
# resolver: https://example.com/snapshots/2018-01-01.yaml
21-
resolver: nightly-2020-03-09
21+
resolver: nightly-2020-03-10
2222

2323
# User packages to be built.
2424
# Various formats can be used as shown in the example below.

stack.yaml.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
packages: []
77
snapshots:
88
- completed:
9-
size: 499083
10-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/3/9.yaml
11-
sha256: 50f89cfb4370c15e4224a34a2316214d54e8a62b19a379fc2b1dc57ea3d5f358
12-
original: nightly-2020-03-09
9+
size: 501929
10+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/3/10.yaml
11+
sha256: b85b932144210a13f4628768d3e7f40bf2071ab0acf932671ff1aadac390d566
12+
original: nightly-2020-03-10

0 commit comments

Comments
 (0)