bacon icon indicating copy to clipboard operation
bacon copied to clipboard

Syntax for incorporating variables in command argument

Open Canop opened this issue 4 weeks ago • 2 comments

Goal is to enable injecting in the commands values coming from

  • some user input (see #404)
  • cargo, eg the MSRV to have a cargo +1.77 check task (see #407)
  • variables defined in the bacon.toml file (may be overriden per task, prefs, etc.)
  • bacon itself (eg the name of the last failing test)
  • other...

I'm not settled on a syntax right now but it must support arguments.

Maybe something like

[jobs.ex-ask]
vars.MSRV = "cargo::msrv"
command = [
    "cargo",
    "+${MSRV}",
    "check",
    "--all-targets",
]
# A task dedicated to checking cargo can be compiled with the MSRV
[jobs.check-msrv]
vars.example_name = {
    source = "user::input",
    question = "Name of the example to run?"
}
command = ["cargo", "run", "--example", "${example_name}"]

Canop avatar Dec 02 '25 08:12 Canop

An alternative to a new vars collection would be to leverage the existing env one, that is

  • making it possible for env variables to be dynamically set up similarly to the above example
  • interpret ${MSRV} in a command argument to interpolate with the env value

Canop avatar Dec 02 '25 12:12 Canop

This is a great idea. Been a bit preoccupied of late. Saw this idea and wanted to second it. Happy to do some testing on this once you have a PoC or give feedback on ideas if desirable.

I think the ${MSRV} syntax is readily readable and if I'm not mistaken shouldn't conflict on any of the OS with their "normal" shell syntax. I think given how we execute the commands we don't actually need to worry about the shell processing what we pass in the end but still better to not mislead users.

c-git avatar Dec 05 '25 01:12 c-git