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

feat: implement a few tera functions for mise toml config #2561

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

erickguan
Copy link
Contributor

I implemented these functions:

  • arch
  • num_cpus
  • os
  • os_family
  • invocation_directory
  • quote
  • kebabcase
  • lowercamelcase
  • shoutykebabcase
  • shoutysnakecase
  • snakecase

Since there are difference from just, I figure it's good to check in before I continue implementing more and add documentation.

  1. PlatformInfo provides "runtime" information as uname. just returns target information. I don't agree on correctness since it will break if you cross-compile. It's always a hassle for package managers. So PlatformInfo API provides a different output than just's.
    I took inspiration from YADM's template design. I provide the result of arch, os, ... as is. This behavior aligns with direnv where direnv exposes no arch information. It's direnv's users job to parse platform information. And for mise, users can use tera filter to transform text.
    What do you think of this?
  2. invocation_directory is annoying to fix. BASE_CONTEXT is initialized lazily so I have difficulty testing other functions (I wrote one test per one custom function). We can come back to this later or refactor the context a bit. I prefer skipping inconsistency for now.
  3. just implements functions like kebabcase as function. I implement them as tera filters. Any objections?
  4. Where should I add documentation? Also, any other thoughts?

Part of #2049

Functions:
- arch
- num_cpus
- os
- os_family
- invocation_directory
- quote
- kebabcase
- lowercamelcase
- shoutykebabcase
- shoutysnakecase
- snakecase
- uppercamelcase
@erickguan erickguan changed the title Implement a few tera functions for mise toml config feat: implement a few tera functions for mise toml config Sep 11, 2024
@jdx jdx merged commit 542a78d into jdx:main Sep 11, 2024
10 checks passed
.render_str("{{ os_family() }}", &Context::default())
.unwrap();

assert_eq!("Linux", result);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already merged this, but it probably could've been DRYed up with if cfg!() macros

@erickguan erickguan deleted the tera-func branch September 12, 2024 18:46
triarius pushed a commit to triarius/mise that referenced this pull request Sep 18, 2024
* Add platform-info to get platform information

* Add num_cpus to get the number of CPU information

* Implement customized tera functions for toml config

Functions:
- arch
- num_cpus
- os
- os_family
- invocation_directory
- quote
- kebabcase
- lowercamelcase
- shoutykebabcase
- shoutysnakecase
- snakecase
- uppercamelcase

* fixup! Implement customized tera functions for toml config

* fixup! Implement customized tera functions for toml config

---------

Co-authored-by: Erick Guan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants