-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
[docs] Explain which conditional blocks are valid in cargo-generate.toml
#1119
Comments
Hey @Andrew15-5, that's a very good question! [target.'cfg(target_arch = "x86_64")'.dependencies] and I found it quite creepy. So I did not found much documentation about it on the toml repo. |
Wait, are you saying cargo-generate is not the one responsible for evaluating the conditional blocks? Then who is? |
Sorry, I found it this code here actually takes care of the conditional evaluation. And, the whole logic is not backed by toml as I thought but by our rhai script hooks. Haven't looked at this code in quite a while. But I guess the whole conversation already reveals that our docs about the whole conditionals feature are not good enough. |
I never used Rhai. Is any valid Rhai conditional statement can be used in the conditional block? Or are there some restrictions? |
it's a simple rhai expression that is evaluated. |
Ok. I'll probably check out Rhai in general to understand what kind of expressions can be evaluated. So that I can insert the most clever and ugly conditional statement in the |
Here is an example from https://github.com/dioxuslabs/dioxus-template (very verbose and repetitive):
original example
It uses the same conditional block as in https://cargo-generate.github.io/cargo-generate/templates/conditional.html.
I don't understand this sentence. IIUC, the "placeholder values", i.e,
.placeholders.<value>
can be used to enable further conditional sections, because depending on which platform I chose the next questions will change depending on the value of theplatform
variable. So maybe this also should be addressed in the docs.I tried using
||
operator in the conditions and surprisingly it worked! So I was able to optimize the config to this:optimized example 1
I was going to ask if conditional is actually a Rust code evaluation, but after another successful optimization:
optimized example 2
I'm almost 100% sure that it is indeed a Rust conditional, or could be a JS? I wasn't able to use
Some
andunwrap
like I can do here:[conditional.'[Some("web").unwrap(), "desktop", "fullstack"].contains(platform)'.placeholders.styling]
(Also, TOML syntax highlighting breaks if I use
[]
inside the'<condition>'
.yj
successfully converts this to YAML and JSON, but fails at converting to TOML. So eitheryj
isn't perfect or above syntax is indeed invalid. Does anyone know which one is true?)So, maybe a restricted version of Rust?
Either way, I didn't find anything even close to "this level" of conditions in the docs, so I think the docs just missing it and should be updated with more examples and an explanation of what you can and can't do in conditional block.
Update: I tried using the optimized syntax and it does generate all the same stuff.
The text was updated successfully, but these errors were encountered: