Skip to content

Commit 7384ed8

Browse files
committed
Add "--enable-future-rundir" and start using the runDir
1 parent bff2338 commit 7384ed8

9 files changed

+40
-28
lines changed

ChangeLog.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog for [hledger-flow](https://github.com/apauley/hledger-flow)
22

3+
## 0.13.2
4+
5+
Improve support for importing a subset of journals: start importing only from the directory given as argument,
6+
or the current directory, and generate only the relevant include files.
7+
8+
This is a behavioural change and (for now) it needs to be enabled with the --enable-future-rundir switch.
9+
This will become the default behaviour in 0.14.x, at which time the switch will be removed.
10+
311
## 0.13.1
412

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

app/Main.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Hledger.Flow.Reports
1313
import Hledger.Flow.CSVImport
1414

1515
data ImportParams = ImportParams { maybeImportBaseDir :: Maybe FilePath
16-
, maybeRunDir :: Maybe FilePath } deriving (Show)
16+
, importUseRunDir :: Bool } deriving (Show)
1717

1818
data ReportParams = ReportParams { maybeReportBaseDir :: Maybe FilePath } deriving (Show)
1919

@@ -36,10 +36,11 @@ main = do
3636

3737
toRuntimeOptionsImport :: MainParams -> ImportParams -> IO RT.RuntimeOptions
3838
toRuntimeOptionsImport mainParams' subParams' = do
39-
(bd, _runDir) <- determineBaseDir $ maybeImportBaseDir subParams'
39+
(bd, runDir) <- determineBaseDir $ maybeImportBaseDir subParams'
4040
hli <- hledgerInfoFromPath $ hledgerPathOpt mainParams'
4141
return RT.RuntimeOptions { RT.baseDir = bd
42-
, RT.importRunDir = maybeRunDir subParams'
42+
, RT.importRunDir = runDir
43+
, RT.useRunDir = importUseRunDir subParams'
4344
, RT.hfVersion = versionInfo'
4445
, RT.hledgerInfo = hli
4546
, RT.sysInfo = systemInfo
@@ -52,7 +53,8 @@ toRuntimeOptionsReport mainParams' subParams' = do
5253
(bd, _) <- determineBaseDir $ maybeReportBaseDir subParams'
5354
hli <- hledgerInfoFromPath $ hledgerPathOpt mainParams'
5455
return RT.RuntimeOptions { RT.baseDir = bd
55-
, RT.importRunDir = Nothing
56+
, RT.importRunDir = "./"
57+
, RT.useRunDir = False
5658
, RT.hfVersion = versionInfo'
5759
, RT.hledgerInfo = hli
5860
, RT.sysInfo = systemInfo
@@ -77,8 +79,8 @@ verboseParser = MainParams
7779

7880
subcommandParserImport :: Parser ImportParams
7981
subcommandParserImport = ImportParams
80-
<$> optional (argPath "dir" "The directory to import. Defaults to the current directory. Use the hledger-flow base directory for a full import.")
81-
<*> optional (strOption (long "experimental-rundir" <> help "A subdirectory of the base where the command will restrict itself to"))
82+
<$> optional (argPath "dir" "The directory to import. Use the base directory for a full import or a sub-directory for a partial import. Defaults to the current directory. This behaviour is changing: see --enable-future-rundir")
83+
<*> switch (long "enable-future-rundir" <> help "Enable the future (0.14.x) default behaviour now: start importing only from the directory that was given as an argument, or the currect directory. Previously a full import was always done. This switch will be removed in 0.14.x")
8284

8385
subcommandParserReport :: Parser ReportParams
8486
subcommandParserReport = ReportParams

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hledger-flow
2-
version: 0.13.1.0
2+
version: 0.13.2.0
33
synopsis: An hledger workflow focusing on automated statement import and classification.
44
category: Finance, Console
55
license: GPL-3

src/Hledger/Flow/CSVImport.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ inputFilePattern = contains (once (oneOf pathSeparators) <> asciiCI "1-in" <> on
3535

3636
importCSVs' :: RuntimeOptions -> TChan FlowTypes.LogMessage -> IO [FilePath]
3737
importCSVs' opts ch = do
38-
channelOutLn ch "Collecting input files..."
39-
let effectiveDir = case importRunDir opts of
40-
Nothing -> (baseDir opts) </> "import"
41-
Just rd -> rd
38+
let baseImportDir = forceTrailingSlash $ (baseDir opts) </> "import"
39+
let runDir = forceTrailingSlash $ collapse $ (baseDir opts) </> (importRunDir opts)
40+
let effectiveDir = if useRunDir opts
41+
then if (forceTrailingSlash $ runDir </> "import") == baseImportDir then baseImportDir else runDir
42+
else baseImportDir
43+
channelOutLn ch $ format ("Collecting input files from "%fp) effectiveDir
4244
(inputFiles, diff) <- time $ single . shellToList . onlyFiles $ find inputFilePattern effectiveDir
4345
let fileCount = length inputFiles
4446
if (fileCount == 0) then
@@ -52,8 +54,7 @@ importCSVs' opts ch = do
5254
channelOutLn ch $ format ("Found "%d%" input files in "%s%". Proceeding with import...") fileCount (repr diff)
5355
let actions = map (extractAndImport opts ch) inputFiles :: [IO FilePath]
5456
importedJournals <- parAwareActions opts actions
55-
let stopAt = forceTrailingSlash $ (baseDir opts) </> "import"
56-
_ <- writeIncludesUpTo opts ch stopAt importedJournals
57+
_ <- writeIncludesUpTo opts ch effectiveDir importedJournals
5758
_ <- writeToplevelAllYearsInclude opts
5859
return importedJournals
5960

src/Hledger/Flow/Common.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ writeFileMap opts ch (m, allYears) = do
400400

401401
writeIncludesUpTo :: (HasBaseDir o, HasVerbosity o) => o -> TChan LogMessage -> FilePath -> [FilePath] -> IO [FilePath]
402402
writeIncludesUpTo _ _ _ [] = return []
403-
writeIncludesUpTo opts ch stopAt paths = do
404-
let shouldStop = any (\dir -> dir == stopAt) $ map parent paths
403+
writeIncludesUpTo opts ch stopAt journalFiles = do
404+
let shouldStop = any (\dir -> dir == stopAt) $ map parent journalFiles
405405
if shouldStop
406-
then return paths
406+
then return journalFiles
407407
else do
408-
newPaths <- groupAndWriteIncludeFiles opts ch paths
409-
writeIncludesUpTo opts ch stopAt newPaths
408+
newJournalFiles <- groupAndWriteIncludeFiles opts ch journalFiles
409+
writeIncludesUpTo opts ch stopAt newJournalFiles
410410

411411
writeToplevelAllYearsInclude :: (HasBaseDir o, HasVerbosity o) => o -> IO [FilePath]
412412
writeToplevelAllYearsInclude opts = do

src/Hledger/Flow/RuntimeOptions.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import Prelude hiding (FilePath, putStrLn)
66
import Hledger.Flow.Types
77

88
data RuntimeOptions = RuntimeOptions { baseDir :: FilePath
9-
, importRunDir :: Maybe FilePath
9+
, importRunDir :: FilePath
10+
, useRunDir :: Bool
1011
, hfVersion :: Text
1112
, hledgerInfo :: HledgerInfo
1213
, sysInfo :: SystemInfo
@@ -17,10 +18,10 @@ data RuntimeOptions = RuntimeOptions { baseDir :: FilePath
1718
deriving (Show)
1819

1920
instance HasVerbosity RuntimeOptions where
20-
verbose (RuntimeOptions _ _ _ _ _ v _ _) = v
21+
verbose (RuntimeOptions _ _ _ _ _ _ v _ _) = v
2122

2223
instance HasSequential RuntimeOptions where
23-
sequential (RuntimeOptions _ _ _ _ _ _ _ sq) = sq
24+
sequential (RuntimeOptions _ _ _ _ _ _ _ _ sq) = sq
2425

2526
instance HasBaseDir RuntimeOptions where
26-
baseDir (RuntimeOptions bd _ _ _ _ _ _ _) = bd
27+
baseDir (RuntimeOptions bd _ _ _ _ _ _ _ _) = bd

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-04
21+
resolver: nightly-2020-03-09
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: 499085
10-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/3/4.yaml
11-
sha256: 0b9c6af3bacc5ad30f63b0818f035632e43367bbbed0ffda4ddec470bd3cffa2
12-
original: nightly-2020-03-04
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

test/TestHelpers.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ defaultHlInfo :: FlowTypes.HledgerInfo
5959
defaultHlInfo = FlowTypes.HledgerInfo "/path/to/hledger" "1.2.3"
6060

6161
defaultOpts :: FilePath -> RuntimeOptions
62-
defaultOpts bd = RuntimeOptions bd Nothing versionInfo' defaultHlInfo systemInfo False False False
62+
defaultOpts bd = RuntimeOptions bd "./" True versionInfo' defaultHlInfo systemInfo False False False
6363

6464
toJournals :: [FilePath] -> [FilePath]
6565
toJournals = map (changePathAndExtension "3-journal" "journal")

0 commit comments

Comments
 (0)