Wish: being able to specify the target year and input journal directory on the command-line
lestephane opened this issue · 3 comments
lestephane commented
I'd like to use the export.hs script as-is because I don't want to diverge from this repo's version, but find myself having to modify it for my specific environment. Would it be possible to have these two variables specifiable using command-line arguments on the export.hs command-line?
- current year (to export up to)
- input journal directory path (
..
is not helpful in my case, as all the files need to be in the same directory, and the parent directory is already calledexport
)
$ git diff
diff --git a/01-getting-started/export/export.hs b/01-getting-started/export/export.hs
index f9330bf..49452ed 100755
--- a/01-getting-started/export/export.hs
+++ b/01-getting-started/export/export.hs
@@ -12,13 +12,13 @@ import System.Directory as D
-- Range of years to report. You would typically want all the years you have data for.
--
first = 2017 :: Int
-current = 2017
+current = 2018
all_years=[first..current]
--
-- Input file naming scheme
--
-input y = printf "../%s.journal" y
+input y = printf "%s.journal" y
--
-- File naming scheme
lestephane commented
My current workaround is to symlink export.sh
into my export
directory, patch it using sed, and invoke the patch version:
#!/bin/bash
# source: https://github.com/adept/full-fledged-hledger/tree/master/01-getting-started/export
my_dir=$(dirname $(readlink -e "$0"))
sed \
-e 's/^input y.*/input y = printf "%s.journal" y/' \
-e "s/^current = .*/current = $(date -d "last year" +%Y)/" \
"${my_dir}/export.hs" > "${my_dir}/patched-export.hs"
"${my_dir}/patched-export.hs" -j --color "$@"
adept commented
I've pushed changes that add --first, --current and --base (run export.sh --help
to see the format).
lestephane commented
Works for me, thanks!
"export.hs" --base=$(pwd) --first=2017 --current="$(date -d "last year" +%Y)"