Skip to content

Commit ced0b70

Browse files
authored
Merge pull request #76 from apauley/rundir
Add an experimental rundir option
2 parents 0564da3 + d2a67fb commit ced0b70

File tree

8 files changed

+31
-32
lines changed

8 files changed

+31
-32
lines changed

ChangeLog.md

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

3+
## 0.13.0
4+
5+
- Add an experimental rundir option for imports
6+
7+
The experimental rundir is an attempt to restrict hledger-flow into processing just a subset of files, primarily to quickly get feedback/failures while adding new accounts to an existing set of accounts.
8+
9+
The use case has been described in [issue 64](https://github.com/apauley/hledger-flow/issues/64).
10+
11+
It is experimental, because the only problem it currently solves is getting hledger-flow to fail fast.
12+
One of the current side effects of doing so is that the generated include files are then written to only
13+
include the subset of files that were processed.
14+
15+
But as soon as you do a full run again, the include files will be correctly re-generated as before.
16+
317
## 0.12.4.0
418

519
- Update usage of hledger to reflect updated command-line flags of hledger version 1.15

app/Main.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import qualified Hledger.Flow.RuntimeOptions as RT
1212
import Hledger.Flow.Reports
1313
import Hledger.Flow.CSVImport
1414

15-
data SubcommandParams = SubcommandParams { maybeBaseDir :: Maybe FilePath } deriving (Show)
15+
data SubcommandParams = SubcommandParams { maybeBaseDir :: Maybe FilePath
16+
, maybeRunDir :: Maybe FilePath } deriving (Show)
1617
data Command = Import SubcommandParams | Report SubcommandParams deriving (Show)
1718

1819
data MainParams = MainParams { verbosity :: Int
@@ -35,6 +36,7 @@ toRuntimeOptions mainParams' subParams' = do
3536
bd <- determineBaseDir $ maybeBaseDir subParams'
3637
hli <- hledgerInfoFromPath $ hledgerPathOpt mainParams'
3738
return RT.RuntimeOptions { RT.baseDir = bd
39+
, RT.runDir = maybeRunDir subParams'
3840
, RT.hfVersion = versionInfo'
3941
, RT.hledgerInfo = hli
4042
, RT.sysInfo = systemInfo
@@ -60,3 +62,4 @@ verboseParser = MainParams
6062
subcommandParser :: Parser SubcommandParams
6163
subcommandParser = SubcommandParams
6264
<$> optional (argPath "basedir" "The hledger-flow base directory")
65+
<*> optional (strOption (long "experimental-rundir" <> help "A subdirectory of the base where the command will restrict itself to"))

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hledger-flow
2-
version: 0.12.4.0
2+
version: 0.13.0.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

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ inputFilePattern = contains (once (oneOf pathSeparators) <> asciiCI "1-in" <> on
3636
importCSVs' :: RuntimeOptions -> TChan FlowTypes.LogMessage -> IO [FilePath]
3737
importCSVs' opts ch = do
3838
channelOutLn ch "Collecting input files..."
39-
(inputFiles, diff) <- time $ single . shellToList . onlyFiles $ find inputFilePattern $ baseDir opts
39+
let effectiveDir = case runDir opts of
40+
Nothing -> (baseDir opts) </> "import"
41+
Just rd -> rd
42+
(inputFiles, diff) <- time $ single . shellToList . onlyFiles $ find inputFilePattern effectiveDir
4043
let fileCount = length inputFiles
4144
if (fileCount == 0) then
4245
do
4346
let msg = format ("I couldn't find any input files underneath "%fp
4447
%"\n\nhledger-flow expects to find its input files in specifically\nnamed directories.\n\n"%
45-
"Have a look at the documentation for a detailed explanation:\n"%s) (dirname (baseDir opts) </> "import/") (docURL "input-files")
48+
"Have a look at the documentation for a detailed explanation:\n"%s) effectiveDir (docURL "input-files")
4649
errExit 1 ch msg []
4750
else
4851
do

src/Hledger/Flow/RuntimeOptions.hs

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

88
data RuntimeOptions = RuntimeOptions { baseDir :: FilePath
9+
, runDir :: Maybe FilePath
910
, hfVersion :: Text
1011
, hledgerInfo :: HledgerInfo
1112
, sysInfo :: SystemInfo
@@ -16,10 +17,10 @@ data RuntimeOptions = RuntimeOptions { baseDir :: FilePath
1617
deriving (Show)
1718

1819
instance HasVerbosity RuntimeOptions where
19-
verbose (RuntimeOptions _ _ _ _ v _ _) = v
20+
verbose (RuntimeOptions _ _ _ _ _ v _ _) = v
2021

2122
instance HasSequential RuntimeOptions where
22-
sequential (RuntimeOptions _ _ _ _ _ _ sq) = sq
23+
sequential (RuntimeOptions _ _ _ _ _ _ _ sq) = sq
2324

2425
instance HasBaseDir RuntimeOptions where
25-
baseDir (RuntimeOptions bd _ _ _ _ _ _) = bd
26+
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: lts-14.9
21+
resolver: nightly-2020-02-04
2222

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

test/Common/Integration.hs

+1-23
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,6 @@ testHiddenFiles = TestCase (
2828
)
2929
)
3030

31-
testDirOrPwd :: Test
32-
testDirOrPwd = TestCase (
33-
sh (
34-
do
35-
currentDir <- fmap (\p -> directory (p </> "t")) pwd
36-
tmpdir <- using (mktempdir "." "hlflow")
37-
let fooDir = collapse $ currentDir </> tmpdir </> "foo/"
38-
let barDir = collapse $ currentDir </> tmpdir </> "bar/"
39-
mkdir fooDir
40-
mkdir barDir
41-
d1 <- liftIO $ dirOrPwd Nothing
42-
liftIO $ assertEqual "dirOrPwd returns pwd as a fallback" currentDir d1
43-
liftIO $ assertEqual "dirOrPwd assumes the fallback is a directory" (directory d1) d1
44-
d2 <- liftIO $ dirOrPwd $ Just $ tmpdir </> "foo"
45-
liftIO $ assertEqual "dirOrPwd returns the supplied dir - no trailing slash supplied" fooDir d2
46-
liftIO $ assertEqual "dirOrPwd assumes the supplied dir is a directory - no trailing slash supplied" (directory d2) d2
47-
d3 <- liftIO $ dirOrPwd $ Just $ tmpdir </> "bar/"
48-
liftIO $ assertEqual "dirOrPwd returns the supplied dir - trailing slash supplied" barDir d3
49-
liftIO $ assertEqual "dirOrPwd assumes the supplied dir is a directory - trailing slash supplied" (directory d3) d3
50-
)
51-
)
52-
5331
assertSubDirsForDetermineBaseDir :: FilePath -> [FilePath] -> IO ()
5432
assertSubDirsForDetermineBaseDir expectedBaseDir importDirs = do
5533
_ <- sequence $ map (assertDetermineBaseDir expectedBaseDir) importDirs
@@ -127,4 +105,4 @@ testFilterPaths = TestCase (
127105
)
128106

129107
tests :: Test
130-
tests = TestList [testDirOrPwd, testDetermineBaseDir, testHiddenFiles, testFilterPaths]
108+
tests = TestList [testDetermineBaseDir, testHiddenFiles, testFilterPaths]

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 versionInfo' defaultHlInfo systemInfo False False False
62+
defaultOpts bd = RuntimeOptions bd Nothing versionInfo' defaultHlInfo systemInfo False False False
6363

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

0 commit comments

Comments
 (0)