@@ -14,58 +14,59 @@ import Hledger.Flow.Common
14
14
import Hledger.Flow.Reports
15
15
import Hledger.Flow.CSVImport
16
16
17
- data SubcommandParams = SubcommandParams { maybeBaseDir :: Maybe FilePath
18
- , hledgerPathOpt :: Maybe FilePath
19
- , showOpts :: Bool
20
- , sequential :: Bool
21
- }
22
- deriving (Show )
17
+ data SubcommandParams = SubcommandParams { maybeBaseDir :: Maybe FilePath } deriving (Show )
23
18
data Command = Import SubcommandParams | Report SubcommandParams deriving (Show )
24
19
25
- data BaseCommand = Version | Command { verbose :: Bool , command :: Command } deriving (Show )
20
+ data MainParams = MainParams { verbose :: Bool
21
+ , hledgerPathOpt :: Maybe FilePath
22
+ , showOpts :: Bool
23
+ , sequential :: Bool
24
+ } deriving (Show )
25
+ data BaseCommand = Version | Command { mainParams :: MainParams , command :: Command } deriving (Show )
26
26
27
27
main :: IO ()
28
28
main = do
29
29
cmd <- options " An hledger workflow focusing on automated statement import and classification:\n https://github.com/apauley/hledger-flow#readme" baseCommandParser
30
30
case cmd of
31
- Version -> stdout $ select versionInfo
32
- Command verbose ' (Import subParams) -> toImportOptions verbose ' subParams >>= importCSVs
33
- Command verbose ' (Report subParams) -> toReportOptions verbose ' subParams >>= generateReports
31
+ Version -> stdout $ select versionInfo
32
+ Command mainParams ' (Import subParams) -> toImportOptions mainParams ' subParams >>= importCSVs
33
+ Command mainParams ' (Report subParams) -> toReportOptions mainParams ' subParams >>= generateReports
34
34
35
- toImportOptions :: Bool -> SubcommandParams -> IO IT. ImportOptions
36
- toImportOptions verbose' params = do
37
- bd <- determineBaseDir $ maybeBaseDir params
38
- hli <- hledgerInfoFromPath $ hledgerPathOpt params
35
+ toImportOptions :: MainParams -> SubcommandParams -> IO IT. ImportOptions
36
+ toImportOptions mainParams' subParams' = do
37
+ bd <- determineBaseDir $ maybeBaseDir subParams'
38
+ hli <- hledgerInfoFromPath $ hledgerPathOpt mainParams'
39
39
return IT. ImportOptions { IT. baseDir = bd
40
40
, IT. hledgerInfo = hli
41
- , IT. verbose = verbose'
42
- , IT. showOptions = showOpts params
43
- , IT. sequential = sequential params }
41
+ , IT. verbose = verbose mainParams '
42
+ , IT. showOptions = showOpts mainParams'
43
+ , IT. sequential = sequential mainParams' }
44
44
45
- toReportOptions :: Bool -> SubcommandParams -> IO RT. ReportOptions
46
- toReportOptions verbose' params = do
47
- bd <- determineBaseDir $ maybeBaseDir params
48
- hli <- hledgerInfoFromPath $ hledgerPathOpt params
45
+ toReportOptions :: MainParams -> SubcommandParams -> IO RT. ReportOptions
46
+ toReportOptions mainParams' subParams' = do
47
+ bd <- determineBaseDir $ maybeBaseDir subParams'
48
+ hli <- hledgerInfoFromPath $ hledgerPathOpt mainParams'
49
49
return RT. ReportOptions { RT. baseDir = bd
50
50
, RT. hledgerInfo = hli
51
- , RT. verbose = verbose'
52
- , RT. showOptions = showOpts params
53
- , RT. sequential = sequential params }
51
+ , RT. verbose = verbose mainParams '
52
+ , RT. showOptions = showOpts mainParams'
53
+ , RT. sequential = sequential mainParams' }
54
54
55
55
baseCommandParser :: Parser BaseCommand
56
56
baseCommandParser = (Command <$> verboseParser <*> commandParser)
57
57
<|> flag' Version (long " version" <> short ' V' <> help " Display version information" )
58
58
59
59
commandParser :: Parser Command
60
- commandParser = fmap Import (subcommand " import" " Converts CSV transactions into categorised journal files" subcommandParser)
60
+ commandParser = fmap Import (subcommand " import" " Converts electronic transactions into categorised journal files" subcommandParser)
61
61
<|> fmap Report (subcommand " report" " Generate Reports" subcommandParser)
62
62
63
- verboseParser :: Parser Bool
64
- verboseParser = switch (long " verbose" <> short ' v' <> help " Print more verbose output" )
63
+ verboseParser :: Parser MainParams
64
+ verboseParser = MainParams
65
+ <$> switch (long " verbose" <> short ' v' <> help " Print more verbose output" )
66
+ <*> optional (optPath " hledger-path" ' H' " The full path to an hledger executable" )
67
+ <*> switch (long " show-options" <> help " Print the options this program will run with" )
68
+ <*> switch (long " sequential" <> help " Disable parallel processing" )
65
69
66
70
subcommandParser :: Parser SubcommandParams
67
71
subcommandParser = SubcommandParams
68
72
<$> optional (argPath " basedir" " The hledger-flow base directory" )
69
- <*> optional (optPath " hledger-path" ' H' " The full path to an hledger executable" )
70
- <*> switch (long " show-options" <> help " Print the options this program will run with" )
71
- <*> switch (long " sequential" <> help " Disable parallel processing" )
0 commit comments