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

Question: Is it possible to use recipe parameters as part of a new parameter before it is passed to the dependencies? #2581

Closed
antis81 opened this issue Jan 16, 2025 · 3 comments

Comments

@antis81
Copy link

antis81 commented Jan 16, 2025

This issue is a bit related to the questions #1988 and #2341. Instead of just forwarding the recipe parameters I would like to create a new (not necessarily variadic) parameter which in turn is forwarded to the recipe.

For a simple example assume a game engine for board/card games and we like to select the game and provide additional parameters from commandline (number of players, size, colors, etc.):

just play-multiplayer "ludo" 6
just play-singleplayer "solitaire"

I am looking for a more flexible way to inject recipe specific parameters.

create game game_args='':
    game-engine --game={{game}} {{game_args}}

play-multiplayer game num_players: (create game "--players={{num_players}}")
    # run game-engine etc.

play-singleplayer game : (create game)
        # run game-engine etc.

I found that it kind of can be achieved with variadic parameters.

# extension to the example justfile
variadic-create game *game_args='':
    game-engine --game={{game}} {{game_args}}


play-multiplayer2 game num_players: (variadic-create game "--players="num_players)
    # run game-engine etc. 

However it puts an additional space character in the output which is not tolerated for my use case.

just play-multiplayer2 "ludo" 6
# output:
game-engine "ludo" --players= 6
                             ^------------  unwanted space here

Is it possible to tell just to "pre-parse" and resolve parameters (as in "--player={{num_players}}") before calling the recipe dependency?

@casey
Copy link
Owner

casey commented Jan 16, 2025

You should be able to use arbitrary expressions in dependency arguments:

play-multiplayer game num_players: (create game "--players=" + num_players")

Although you might need parenthesis to avoid ambiguity:

play-multiplayer game num_players: (create game ("--players=" + num_players"))

Does that work?

@antis81
Copy link
Author

antis81 commented Jan 17, 2025

Okay I didn't know about string concatenation is possible here. Yes it works thank you!

@antis81 antis81 closed this as completed Jan 17, 2025
@casey
Copy link
Owner

casey commented Jan 17, 2025

Nice, glad to hear!

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