den icon indicating copy to clipboard operation
den copied to clipboard

FR: Simple glob syntax for Angle Brackets

Open theutz opened this issue 7 months ago • 7 comments

More syntax sugar for includes, like:

<cli/{*}>          # includes all sub-aspects for this aspect (alias for attrValues trick?)
<cli/{btop,bat}>   # expands to include `cli._.btop` and `cli._.bat`

Originally posted by @theutz in https://github.com/vic/den/discussions/329#discussioncomment-16474776

theutz avatar Apr 07 '26 19:04 theutz

My recommendation is just create a function getAttrByGlob that takes the same arguments as lib.getAttrByPath, and replace usage of the later in our angle brackets implementation. Tests can use getAttrByGlob directly to test globs work correctly. And then have other tests that ensure the result is an aspect including aspects that match the glob.

vic avatar Apr 08 '26 05:04 vic

@theutz what if I name my provider "btop,bat" because I'm a monster

... what if I name it "*"? :)

sini avatar Apr 08 '26 05:04 sini

I suppose we'd have to add to the docs that, if you're going to use __findFile, you can't have { } , * in the names? I can try and provide a good error message.

Do you think we should fallback to a literal reading of the filename if the glob fails but literal doesn't?

theutz avatar Apr 08 '26 06:04 theutz

Do you think we should fallback to a literal reading of the filename if the glob fails but literal doesn't?

No. No file-system access from Den, no imports. Our __findFile is named like that just for the angle bracket Nix syntax to work, but it is nothing related to files.

vic avatar Apr 08 '26 07:04 vic

Sorry, I mistyped there. Should've written:

Do you think we should fallback to a literal reading of the aspect name?

theutz avatar Apr 08 '26 07:04 theutz

Oh you mean if foo,bar does not match, try a literal foo,bar named aspect ? yeah, sounds good.

vic avatar Apr 08 '26 07:04 vic

See also: https://github.com/vic/den/pull/401#issuecomment-4208832044

vic avatar Apr 08 '26 19:04 vic