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