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

Can't use Just variable inside if statement #758

Closed
DeflatedPickle opened this issue Feb 15, 2021 · 1 comment
Closed

Can't use Just variable inside if statement #758

DeflatedPickle opened this issue Feb 15, 2021 · 1 comment

Comments

@DeflatedPickle
Copy link

First of all, I'm just in love with just! Thank you so much for dedicating so much time and effort towards this project and the documentation for it

I've found a possible quirk, given my understanding of conditionals and mid-string-variables is correct
Consider the following;

build debug='all':
	#!/usr/bin/env bash
	set -euxo pipefail
	debug={{ if debug != '' { "--debug {{ debug }}" } else { "" } }}

If I'm getting the syntax right, this should resolve to debug="--debug all", however the string inside of the if statement isn't processed and we get the following trace:

+ debug=--debug
+ '{{' debug '}}'
/tmp/justZ7hT4U/build: line 91: {{: command not found
error: Recipe `build` failed with exit code 127

The following does work, since the work is done by bash;

if [ {{ debug }} != "" ]; then debug="--debug {{ debug }}"; else debug=""; fi

But this isn't what I thought of first as my use-case was to have this check as an argument to a script and I wanted to cut corners. But I might just be getting my syntax wrong, wouldn't be the first time

@casey
Copy link
Owner

casey commented Feb 16, 2021

First of all, I'm just in love with just! Thank you so much for dedicating so much time and effort towards this project and the documentation for it

Awesome, I'm glad you like it!

Ah, so variable interpolation is only currently supported in recipe bodies, and not inside strings. I'd like to support this eventually with a python f-string like syntax, e.g.:

build debug='all':
	#!/usr/bin/env bash
	set -euxo pipefail
	debug={{ if debug != '' { f"--debug {{ debug }}" } else { "" } }}

This is tracked in #11, so I'll close this in favor of that issue. You can tell it's a longstanding request, since it's issue number 11 😅.

I've put it off for so long because it's pretty tricky. I think it requires that the lexer get some kind of state stack, so it can track when it's inside of nested interpolations.

@casey casey closed this as completed Feb 16, 2021
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

No branches or pull requests

2 participants