@@ -20,8 +20,12 @@ import Data.Time.LocalTime
20
20
import Data.Function (on )
21
21
import qualified Data.List as List (nub , null , sort , sortBy , groupBy )
22
22
import Data.Ord (comparing )
23
+
23
24
import Hledger.Flow.Types
24
25
import qualified Hledger.Flow.Import.Types as IT
26
+ import Hledger.Flow.BaseDir (turtleBaseDir , relativeToBase , relativeToBase' )
27
+ import Hledger.Flow.DocHelpers (docURL )
28
+
25
29
import Control.Concurrent.STM
26
30
27
31
import qualified Data.List.NonEmpty as NE
@@ -207,13 +211,6 @@ verboseTestFile opts ch p = do
207
211
else logVerbose opts ch $ format (" Did not find a " % fp% " file at '" % fp% " '" ) (basename rel) rel
208
212
return fileExists
209
213
210
- relativeToBase :: HasBaseDir o => o -> FilePath -> FilePath
211
- relativeToBase opts = relativeToBase' (baseDir opts)
212
-
213
- relativeToBase' :: FilePath -> FilePath -> FilePath
214
- relativeToBase' bd p = if forceTrailingSlash bd == forceTrailingSlash p then " ./" else
215
- fromMaybe p $ stripPrefix (forceTrailingSlash bd) p
216
-
217
214
groupPairs' :: (Eq a , Ord a ) => [(a , b )] -> [(a , [b ])]
218
215
groupPairs' = map (\ ll -> (fst . head $ ll, map snd ll)) . List. groupBy ((==) `on` fst )
219
216
. List. sortBy (comparing fst )
@@ -257,9 +254,6 @@ allYearIncludeFiles m = (m, yearsIncludeMap $ Map.keys m)
257
254
yearsIncludeMap :: [FilePath ] -> InputFileBundle
258
255
yearsIncludeMap = groupValuesBy allYearsPath
259
256
260
- docURL :: Line -> Text
261
- docURL = format (" https://github.com/apauley/hledger-flow#" % l)
262
-
263
257
lsDirs :: FilePath -> Shell FilePath
264
258
lsDirs = onlyDirs . ls
265
259
@@ -410,7 +404,7 @@ writeIncludesUpTo opts ch stopAt journalFiles = do
410
404
411
405
writeToplevelAllYearsInclude :: (HasBaseDir o , HasVerbosity o ) => o -> IO [FilePath ]
412
406
writeToplevelAllYearsInclude opts = do
413
- let allTop = Map. singleton (baseDir opts </> allYearsFileName) [" import" </> allYearsFileName]
407
+ let allTop = Map. singleton (turtleBaseDir opts </> allYearsFileName) [" import" </> allYearsFileName]
414
408
writeFiles' $ (addPreamble . toIncludeFiles' Map. empty Map. empty) allTop
415
409
416
410
changeExtension :: Text -> FilePath -> FilePath
@@ -423,55 +417,6 @@ changeOutputPath :: FilePath -> FilePath -> FilePath
423
417
changeOutputPath newOutputLocation srcFile = mconcat $ map changeSrcDir $ splitDirectories srcFile
424
418
where changeSrcDir file = if (file == " 1-in/" || file == " 2-preprocessed/" ) then newOutputLocation else file
425
419
426
- errorMessageBaseDir :: FilePath -> Text
427
- errorMessageBaseDir startDir = format (" \n Unable to find an hledger-flow import directory at '" % fp
428
- % " ' (or in any of its parent directories).\n\n "
429
- % " Have a look at the documentation for more information:\n " % s% " \n " )
430
- startDir (docURL " getting-started" )
431
-
432
- determineBaseDir :: Maybe FilePath -> IO (FilePath , FilePath )
433
- determineBaseDir (Just suppliedDir) = determineBaseDir' suppliedDir
434
- determineBaseDir Nothing = pwd >>= determineBaseDir'
435
-
436
- determineBaseDir' :: FilePath -> IO (FilePath , FilePath )
437
- determineBaseDir' startDir = do
438
- currentDir <- pwd
439
- let absoluteStartDir = if relative startDir then collapse (currentDir </> startDir) else startDir
440
- ebd <- determineBaseDirFromAbsoluteStartDir absoluteStartDir
441
- case ebd of
442
- Right bd -> return bd
443
- Left t -> die t
444
-
445
- determineBaseDirFromAbsoluteStartDir :: FilePath -> IO (Either Text (FilePath , FilePath ))
446
- determineBaseDirFromAbsoluteStartDir absoluteStartDir = determineBaseDirFromAbsoluteStartDir' absoluteStartDir absoluteStartDir
447
-
448
- determineBaseDirFromAbsoluteStartDir' :: FilePath -> FilePath -> IO (Either Text (FilePath , FilePath ))
449
- determineBaseDirFromAbsoluteStartDir' startDir possibleBaseDir = do
450
- possibleBDExists <- testdir possibleBaseDir
451
- if not possibleBDExists then return $ Left $ format (" The provided directory does not exist: " % fp) possibleBaseDir
452
- else
453
- if relative startDir || relative possibleBaseDir then
454
- return $ Left $ format (" Internal error: found a relative path when expecting only absolute paths:\n " % fp% " \n " % fp% " \n " ) startDir possibleBaseDir
455
- else do
456
- foundBaseDir <- testdir $ possibleBaseDir </> " import"
457
- if foundBaseDir then
458
- do
459
- let baseD = forceTrailingSlash possibleBaseDir
460
- let runDir = forceTrailingSlash $ relativeToBase' baseD startDir
461
- return $ Right $ (baseD, runDir)
462
- else do
463
- let doneSearching = (possibleBaseDir `elem` [" /" , " ./" ])
464
- if doneSearching
465
- then return $ Left $ errorMessageBaseDir startDir
466
- else determineBaseDirFromAbsoluteStartDir' startDir $ parent possibleBaseDir
467
-
468
-
469
- dirOrPwd :: Maybe FilePath -> IO FilePath
470
- dirOrPwd maybeBaseDir = fmap forceTrailingSlash (fromMaybe pwd $ fmap realpath maybeBaseDir)
471
-
472
- forceTrailingSlash :: FilePath -> FilePath
473
- forceTrailingSlash p = directory (p </> " temp" )
474
-
475
420
importDirBreakdown :: FilePath -> [FilePath ]
476
421
importDirBreakdown = importDirBreakdown' []
477
422
@@ -493,7 +438,7 @@ extractImportDirs inputFile = do
493
438
" Have a look at the documentation for a detailed explanation:\n " % s) inputFile (docURL " input-files" )
494
439
495
440
listOwners :: HasBaseDir o => o -> Shell FilePath
496
- listOwners opts = fmap basename $ lsDirs $ (baseDir opts) </> " import"
441
+ listOwners opts = fmap basename $ lsDirs $ (turtleBaseDir opts) </> " import"
497
442
498
443
intPath :: Integer -> FilePath
499
444
intPath = fromText . (format d)
0 commit comments