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

Provide a value for flag() to be set when the value is provided #4238

Open
jdx opened this issue Jan 27, 2025 · 1 comment
Open

Provide a value for flag() to be set when the value is provided #4238

jdx opened this issue Jan 27, 2025 · 1 comment
Labels

Comments

@jdx
Copy link
Owner

jdx commented Jan 27, 2025

Discussed in #4237

Originally posted by zephraph January 26, 2025
2025.1.15 macos-arm64 (2025-01-26)

Okay, so I have a mise task that builds a rust crate. I want a windows option (to tell it to build for windows). When it has that option, I want to run cargo xwin build instead of cargo build. (Note I'm doing cross compilation so run_windows won't work for this case).

Here's the monstrosity I have right now

[!NOTE]
This doesn't actually work, I was misreading the output.

[tasks."build:rust"]
run = """
{% set windows = flag(name='windows', default='') %}
{% if windows == 'true' %}
  {% set xwin = 'xwin ' %}
{% else %}
  {% set xwin = '' %}
{% endif %}
echo {{ xwin }}
cargo {{ xwin }}build --bin webview -F {{option(name='features', var=true, default='transparent devtools')}}
"""

There's a lot of problems to discuss:

  1. I'm not using general sh logic as the docs recommend because the logs only show the first line of output. So if I added an echo 'hello' to the above script the logs would look like this
[build:rust] $ echo hello

I really just want to see the command output (the last line in this case). That's a bit of a separate issue, but still one to note.

  1. It would seem like `{{ flag(name='windows', default='') | replace(from='true', to='xwin') }} should work if it's returning a string. Doesn't seem to be though.
  2. cargo {% if flag(name='windows') %}xwin{% endif %} build seems like it should work, but that throws an exception b/c flag doesn't return a boolean
  3. cargo {% if flag(name='windows') == 'true' %}xwin{% endif %} build doesn't work either

What I'd like to see

One solution that would be nice is just adding an arg to flag that would be the value if it's true. E.g.

{{ flag(name='windows', value='xwin') }}

Another would be to have flag just return a string. I've looked through the code and it looks like it's return some sort of template string that's more of a key? It's weird, because I can't usually get it to print out (it usually just prints as true or nothing).

e.g.

echo '{{ flag(name='windows') }}'

with --window passed will echo true

without it it will echo nothing (e.g. just run echo '')

Funnily, you can see the template string weirdness when you pass it through the reverse filter

echo '{{ flag(name='windows') | reverse }}'

will print GRA_KSAT_ESIM:swodniw:GRA_KSAT_ESIM. This special type doesn't play well with anything else. If we could at least have something we could do to normalize it into a string we'd have some more options.

Thoughts? Recommendations?

@jdx
Copy link
Owner Author

jdx commented Feb 1, 2025

I think my solution to having special strings for flags is not good enough. I think a real solution where the template output is the flag value is what needs to happen in order for templates to work the way users expect.

@jdx jdx added the bug label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant