hledger
hledger copied to clipboard
directives don't affect other journal files
In the report linked at https://twitter.com/LedgerTips/status/830238616261586945, I wanted to apply some journal directives to affect formatting of the output. I expected this to work:
$ echo "commodity 0,000,000 bytes" > tarsnap.preamble.journal
$ hledger -f tarsnap.preamble.journal -f tarsnap.csv bal
It didn't, nor does hledger -f tarsnap.preamble.journal -f tarsnap.journal ..., because directives affect only the file they are in, and not other files specified with additional -f arguments.
Ideally, this would just work, but there might be some complexities. Should directives affect subsequent files on the command line, or all files specified ? Should they affect just journal files, or all file types ? Would some directives work differently from others ? (Eg some directives are location-independent and some are not.)
I thought this was a feature. You can have a separate file for your vacation expenses where you use different aliases. Note that includes inside of the file with directives will be affected also. This allows you to have a hierarchy of files and apply stuff only at some level.
Unless there will be directives like begin tag/end tag and begin alias/end alias I wouldn't like to loose such functionality.
Other option would be to use export or alike prefix for directives to make them global.
...once I understood this behavior with regard to account aliases, I ended up with this explanation for this: included files in hledger are like parallel circuits, and the directives are not shared between them / the included files; they have to be defined in the main file, only then they are inherited.
This is different from ledger-cli, where i.e. account aliases of included files are propagated to every other file of the tree / bunch.
I like to have a separate accounts.journal file with my chart of accounts and account alias definition.
If I put that file as an included file of my main.journal, ledger-cli substitutes the alias in every included file, hledger doesn't.
I ended up with reiterating the account alias definition from my accounts.journal into the main.journal, so I can play with both programs.
Correct @5472qaywsx, and https://hledger.org/journal.html#aliases-and-multiple-files says something similar nowadays. This is still surprising to people and I think docs can be improved further. [Eg at https://hledger.org/journal.html#directives]