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

implement more tera functions #2049

Closed
jdx opened this issue May 10, 2024 · 7 comments · Fixed by #2582
Closed

implement more tera functions #2049

jdx opened this issue May 10, 2024 · 7 comments · Fixed by #2582
Labels
enhancement New feature or request

Comments

@jdx
Copy link
Owner

jdx commented May 10, 2024

just has quite a few functions which is a good starting point for us to improve what can be done with templates in mise

@jdx jdx added the enhancement New feature or request label May 10, 2024
@tfh-cri
Copy link

tfh-cri commented May 29, 2024

some equivalent to the tera built-in slugify would be useful (in my current need, adding a git-branch specific suffix to a python virtualenv managed by mise).

I assumed the tera builtin would already work, but looks like mise is using the

tera = { ..., default-features = false }

definition which removes various functions including slugify.

A haphazard local rebuild suggests default-features = true adds about 3MB to the final binary (23->26MB), so might be excessive for just that function.

@jdx
Copy link
Owner Author

jdx commented May 30, 2024

I'd accept a pr to add that feature for sure

@jdx
Copy link
Owner Author

jdx commented May 30, 2024

in fact all the default ones seem like they could be useful

@erickguan
Copy link
Contributor

erickguan commented Sep 8, 2024

I plan to implement this in 3 steps.

  1. I will implement functions with "strict" definitions. They are;
  • system information
  • Environment Variables
  • Invocation Directory
  • Source and Source Directory
  • String Manipulation
  • Path Manipulation
  • UUID and Hash Generation
  • Semantic Versions
  1. After that, we can discuss how to handle errors for other functions generating runtime failures and filesystem, shell access. I have not thought about security, etc.
  2. Then the other functions you consider make sense. e.g. no point implementing justfile.

What do you think of it?

@jdx
Copy link
Owner Author

jdx commented Sep 9, 2024

tera already supports some of this but for what it doesn't have support this sounds fine

@erickguan
Copy link
Contributor

Now we have added most of just functions, at least within PRs. A quick question and some progress updates.

Do you want to improve error handling or it's a future improvment? You don't use tera::Error which generally provides a few more error information. The current way of throwing error via CLI is fine judging no one complains.

You mentioned invocation_directory and other paths in #2569. I saw some XDG paths in env.rs but not more than that. I will leave them to you.

Then the last few functions are:

  • Error Reporting
  • Random
  • Datetime

I don't see a point implementing just_exexcutable nor just_pid functions. is_dependency is not relevant because mise is not a build system.

@jdx
Copy link
Owner Author

jdx commented Sep 15, 2024

Do you want to improve error handling

yeah, doesn't have to be a part of this issue necessarily though

You mentioned invocation_directory and other paths in #2569. I saw some XDG paths in env.rs but not more than that. I will leave them to you.

I added cwd and config_root which I think should suffice: https://mise.jdx.dev/templates.html

I don't see a point implementing just_exexcutable nor just_pid functions.

I think these could be useful, especially mise_executable—probably on the context object as variables though not as functions. These should be available in env.rs somewhere.

I think we should still add support for absolute as well as the xdg path variables (xdg should just be on the context object). xdg should be easy, just add these to the context object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants