Skip to content

Commit 1729200

Browse files
authored
Merge pull request #44 from apauley/move-cli-options
Re-organise the command-line interface
2 parents 4b7c95a + f3898cc commit 1729200

File tree

7 files changed

+55
-42
lines changed

7 files changed

+55
-42
lines changed

.circleci/config.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- run:
2626
name: Install hledger-flow executable
2727
command: stack install
28+
- run:
29+
name: hledger-flow --help
30+
command: ~/.local/bin/hledger-flow --help
2831
- run:
2932
name: hledger-flow --version
3033
command: ~/.local/bin/hledger-flow --version
@@ -45,10 +48,10 @@ jobs:
4548
command: git clone --recurse-submodules https://github.com/apauley/hledger-flow-example.git $HOME/hledger-flow-example
4649
- run:
4750
name: hledger-flow import
48-
command: ~/.local/bin/hledger-flow --verbose import --show-options $HOME/hledger-flow-example
51+
command: ~/.local/bin/hledger-flow --verbose --show-options import $HOME/hledger-flow-example
4952
- run:
5053
name: hledger-flow report
51-
command: ~/.local/bin/hledger-flow --verbose report --show-options $HOME/hledger-flow-example
54+
command: ~/.local/bin/hledger-flow --verbose --show-options report $HOME/hledger-flow-example
5255
- run:
5356
name: Undo package.yaml change before cache_save
5457
command: git checkout HEAD package.yaml

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ install:
4545
- stack build --interleaved-output --test --bench --no-run-tests --no-run-benchmarks
4646
- stack install
4747
- which hledger-flow
48+
- hledger-flow --help
4849
- hledger-flow --version
4950
- ldd $(which hledger-flow) || true
5051
- ./bin/release-tarball ~/.local/bin/hledger-flow
@@ -56,8 +57,8 @@ install:
5657
script:
5758
- stack test --interleaved-output
5859
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git checkout HEAD package.yaml; fi
59-
- hledger-flow --verbose import --show-options $HOME/hledger-flow-example
60-
- hledger-flow --verbose report --show-options $HOME/hledger-flow-example
60+
- hledger-flow --verbose --show-options import $HOME/hledger-flow-example
61+
- hledger-flow --verbose --show-options report $HOME/hledger-flow-example
6162

6263
deploy:
6364
- provider: releases

ChangeLog.md

Lines changed: 8 additions & 0 deletions
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.12.0
4+
5+
- Re-organised the command-line interface:
6+
moved various command-line options out of subcommands, into the top-level.
7+
- Added a [contributor's agreement](https://github.com/apauley/hledger-flow/blob/master/CONTRIBUTING.org)
8+
after receiving some more valued contributions from
9+
[jecaro](https://github.com/apauley/hledger-flow/pull/42)
10+
311
## 0.11.3
412

513
- Detect the hledger-flow base directory correctly, even when in a subdirectory. Similar to how git behaves.

README.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ likely change.
113113

114114
Let me know if you can think of some improvements.
115115

116-
* Detailed Step-By-Step Guide
116+
* Getting Started
117117
:PROPERTIES:
118-
:CUSTOM_ID: detailed-step-by-step-guide
118+
:CUSTOM_ID: getting-started
119119
:END:
120120

121121
Have a look at the [[file:docs/README.org][detailed step-by-step

app/Main.hs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,59 @@ import Hledger.Flow.Common
1414
import Hledger.Flow.Reports
1515
import Hledger.Flow.CSVImport
1616

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)
2318
data Command = Import SubcommandParams | Report SubcommandParams deriving (Show)
2419

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)
2626

2727
main :: IO ()
2828
main = do
2929
cmd <- options "An hledger workflow focusing on automated statement import and classification:\nhttps://github.com/apauley/hledger-flow#readme" baseCommandParser
3030
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
3434

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'
3939
return IT.ImportOptions { IT.baseDir = bd
4040
, 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' }
4444

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'
4949
return RT.ReportOptions { RT.baseDir = bd
5050
, 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' }
5454

5555
baseCommandParser :: Parser BaseCommand
5656
baseCommandParser = (Command <$> verboseParser <*> commandParser)
5757
<|> flag' Version (long "version" <> short 'V' <> help "Display version information")
5858

5959
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)
6161
<|> fmap Report (subcommand "report" "Generate Reports" subcommandParser)
6262

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")
6569

6670
subcommandParser :: Parser SubcommandParams
6771
subcommandParser = SubcommandParams
6872
<$> 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")

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hledger-flow
2-
version: 0.11.3.0
2+
version: 0.12.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/Common.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,19 +393,19 @@ changeOutputPath newOutputLocation srcFile = mconcat $ map changeSrcDir $ splitD
393393
where changeSrcDir file = if (file == "1-in/" || file == "2-preprocessed/") then newOutputLocation else file
394394

395395
errorMessageBaseDir :: FilePath -> Text
396-
errorMessageBaseDir startDir = format ("Unable to find an hledger-flow import directory at '"%fp
396+
errorMessageBaseDir startDir = format ("\nUnable to find an hledger-flow import directory at '"%fp
397397
%"' (or in any of its parent directories).\n\n"
398-
%"Have a look at the documentation for more information:\n"%s)
399-
startDir (docURL "input-files")
398+
%"Have a look at the documentation for more information:\n"%s%"\n")
399+
startDir (docURL "getting-started")
400400

401401
determineBaseDir :: Maybe FilePath -> IO FilePath
402402
determineBaseDir (Just suppliedDir) = determineBaseDir' suppliedDir
403403
determineBaseDir Nothing = pwd >>= determineBaseDir'
404404

405405
determineBaseDir' :: FilePath -> IO FilePath
406406
determineBaseDir' startDir = do
407-
ee <- determineBaseDir'' startDir startDir
408-
case ee of
407+
ebd <- determineBaseDir'' startDir startDir
408+
case ebd of
409409
Right bd -> return bd
410410
Left t -> die t
411411

0 commit comments

Comments
 (0)