JanDeDobbeleer / aliae

Cross shell and platform alias management
https://aliae.dev
MIT License
73 stars 3 forks source link

feat: adding !include and !include_dir #101

Closed kiliantyler closed 2 months ago

kiliantyler commented 3 months ago

Prerequisites

Reasoning

With this project being focused on cleaning up shell startups and organizing dotfiles it seems like a generally good strategy to not have a gigantic single .aliae.yaml file.

Technically this can be accomplished with multiple calls to aliae and changing the --config parameter each time, but that is clunky and not very intuitive.

This brings the generally accepted yaml tag of "!include" as well as "!include_dir" to aliae. I searched around for any go-yaml libraries that had native support for adding tags to yaml unmarshaling, but came up empty handed. goccy/go-yaml does not provide a fantastic way to process yaml tags so preprocessing is required.

With the preprocessing I wanted it to have a few features:

  1. !include - Include a file directly
  2. !include_dir - Include an entire directory of .yaml files, allowing "infinite" management
  3. Imports are templated (i.e. "{{.Home}}" works)
  4. Imports accept relative imports (i.e. "./" works)
  5. Recursive imports

Due to a few of these "requirements" I had to move around some things to avoid cyclical imports, mostly the logic around getting the config file location so that relative imports work.

If there are any questions or suggestions I am happy to hear anything!

Thanks for this awesome tool!

JanDeDobbeleer commented 3 months ago

@kiliantyler thanks for this contribution! I'm going to have a look over the week, I have quite a few pointers on style and naming, but really really interesting addition. I will probably create a refactoring commit on top so you can also have a look, I feel that if I have to work with comments, it might get discouraging and that's definitely not the goal here.

kiliantyler commented 3 months ago

Not a problem at all! Won't bother me what you do to it, I'm much more on the "SRE" side of things so coding isn't my strongest suit and I knew it wouldn't be totally right on the first try.

Let me know if you need any parts explained or anything!

JanDeDobbeleer commented 2 months ago

@kiliantyler I'm still going to rewrite the tests as the way they are written, it will fail (and they're not extensible). But this also seems to work. I moved the logic back to config, where I feel it belongs and was able to remove the duplicate struct by not setting the custom marchaler on the global level and using a new decoder internally.

JanDeDobbeleer commented 2 months ago

@all-contributors please add @kiliantyler for code,doc

This is pure magic 🪄! @holopin-bot @kiliantyler wizard

holopin-bot[bot] commented 2 months ago

Congratulations @kiliantyler, you just earned a badge! Here it is: https://holopin.io/claim/cluqohzz113280fi9lvq9nceu

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

allcontributors[bot] commented 2 months ago

@JanDeDobbeleer

I've put up a pull request to add @kiliantyler! :tada: