Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line wildcard for reading several files (without multiple -f) ? #2290

Open
edpichler opened this issue Nov 21, 2024 · 10 comments
Open
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. cli Command line parsing, options, arguments and suchlike.

Comments

@edpichler
Copy link

I would like to use the argument -f to add files of an entire directory (representing a year), is it possible?

@simonmichael
Copy link
Owner

simonmichael commented Nov 21, 2024

I often wish for that too. It's not currently possible; at times I have used shell scripts to generate the multiple -f's.

Enhancements considered:

  • -F/--files '2023/* 2024/*' - the quotes would be required, a bit clunky
  • hledger ... -- 2023/* 2024/* - multiple file arguments allowed after --, also a bit clunky

What other things could we do ?

@simonmichael
Copy link
Owner

  • -f '2023/*' - if -f's usual argument contains a * or a ?, treat it as a glob generating multiple -f's. (Reuses -f, but a glob character must be used, unlike -F above.)

@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. cli Command line parsing, options, arguments and suchlike. labels Nov 21, 2024
@edpichler
Copy link
Author

edpichler commented Nov 21, 2024

I thought something like hledger -f 2023/* -f 2024/*.dat -f index.dat would be nice.

Edit
-f 2023/** and -f 2024/**.dat where double ** could read sub dirs, maybe. A git/glob style?

@simonmichael
Copy link
Owner

That doesn't work, because the shell will expand that to

hledger -f 2023/file1 2023/file2 -f 2024/file1.dat 2024/file2.dat -f index.dat

which can't be parsed sensibly.

@edpichler
Copy link
Author

I forgot we have this:
image

It will help in my current multi-file problem. I can create index files with the references I need.

@simonmichael simonmichael changed the title Wildcards for several files? command line wildcard for reading several files (without multiple -f) ? Dec 3, 2024
@larsks
Copy link

larsks commented Dec 31, 2024

What if you could pass a directory as the argument to -f instead of a file, and then have hledger operate on all the files in that directory? That means we don't need to deal with the problem that @simonmichael pointed out, but you still get a nice syntax for operating on batches of files:

hl import -f data/mycreditcard/

@simonmichael
Copy link
Owner

That sounds fine too, but only when you have no other kinds of file in the directory.

@simonmichael
Copy link
Owner

simonmichael commented Jan 7, 2025

I think a directory often contains files that include each other. In that case, reading all files would not be desirable, as the includes will cause some of them to be read a second time, duplicating the data.

Instead, how about reading the file named like the directory, if any. Eg:

2025/
 2025.journal           <- read this file, because its base name matches the directory
 2025-accounts.journal
 2025-tags.journal
 2025-prices.journal

If no similarly-named file is found, it could default to reading the alphabetically first ? So you could designate the main file by prefixing a 0, _, or capitalising its name.

@edpichler
Copy link
Author

edpichler commented Jan 8, 2025

@simonmichael I like the principle of "less is more".

I started this thread but I realised we can reference files from inside of it. So having an index.dat and referencing other files might be a good solution (at least for my use case) without increasing the code base and maintenance costs. Moreover, the current solution is less error prone. Undesired files could be referenced and wrong decisions could be made accepting wildcards, for instance.

@simonmichael
Copy link
Owner

simonmichael commented Jan 8, 2025

+1 to that principle.

I think I like the idea of using a directory-named file as the index. More useful than a generic "index.journal" name.

(Currently doing cleanup of old journals, and I am quite often typing -f YYYY/YYYY.journal)

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, hare-brained proposal, or plea. cli Command line parsing, options, arguments and suchlike.
Projects
None yet
Development

No branches or pull requests

3 participants