Add "%l" substitution for source commands - #2695
Conversation
This adds a "%l" date that can be used in commands to get the "latest" recording. The idea is you can tell your tool something like: source | mytool --since=%l and only fetch new data.
|
Thanks for the PR @matthewbauer. Note our https://hledger.org/PULLREQUESTS.html / AI policies - you might need to do a small manual PR before this one. I think we'd avoid adding a --latest-if-none-defined option. Adding support for special interpolations in the "Latest date" is the same date that's in .latest.* files I guess ? Note that date can be repeated to express multiple transactions seen on that date; we'd want a way to represent that. I wonder how else your use case could be solved. |
|
Yeah I'm open to other ideas, but it seems like you do need some kind of "cursor" if you want to efficiently deal with lots of data from a 3rd party. "Latest date" is intended to be the first date in the .latest, with the idea that you probably want to be inclusive of that, and have hledger decide whether to include or exclude those. |
This adds a "%l" date that can be used in commands to get the "latest" recording. The idea is you can put in your rules something like:
and the tool knows when the earliest date is.
The issue with this is that on the first run, you will not have a latest date. It's kind of hard to encode an "if else" in a command substitution, so it makes sense to just provide some value you know you will not have data before. Hence the new "latest-if-none-defined" option, which is intended to be set to something very far in the past like 2000-01-01. We could make this have a default, but for now it seems reasonable to configure it manually.
See https://gist.github.com/matthewbauer/08a58a61286a8a2eab89d5f7a1a4a8a0 for an example of rules that could use this feature.
Does this seem like a feature you'd like to support? I omitted any documentation beyond the CLI flags, but can add it if desired.
Note: this was first written by an AI agent but I've since tweaked it pretty extensively.