Skip to content

Add "%l" substitution for source commands - #2695

Open
matthewbauer wants to merge 1 commit into
simonmichael:mainfrom
matthewbauer:add-%l-to-command
Open

Add "%l" substitution for source commands#2695
matthewbauer wants to merge 1 commit into
simonmichael:mainfrom
matthewbauer:add-%l-to-command

Conversation

@matthewbauer

@matthewbauer matthewbauer commented Aug 17, 2026

Copy link
Copy Markdown

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:

  source | mytool --since=%l

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.

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.
@simonmichael

Copy link
Copy Markdown
Owner

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 source rule is interesting. It also seems like a slippery slope - we'd begin defining yet another custom domain specific language, which would never be finished.

"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.

@simonmichael simonmichael added A-WISH Some kind of improvement request or proposal. needs-discussion To unblock: needs more discussion/review/exploration csv The csv file format, csv output format, or generally CSV-related. labels Aug 22, 2026
@matthewbauer

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-WISH Some kind of improvement request or proposal. csv The csv file format, csv output format, or generally CSV-related. needs-discussion To unblock: needs more discussion/review/exploration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants