bazel-tools icon indicating copy to clipboard operation
bazel-tools copied to clipboard

Multirun option to select only one command to pass command line arguments to

Open augray opened this issue 3 years ago • 4 comments

Some circumstances may involve calling multiple run targets, with only one of them actually needing command line arguments. The current behavior is that all run targets get the arguments passed to them, which makes it so users have to "hack around" the fact that the others should not get the arguments. Ideal interface:

multirun(
    name = "bar",
    commands = [
        "cmd_1",
        "cmd_2",
    ],
    
    # when doing `bazel run //foo:bar -- --some --arguments`
    # only cmd_1 should see `--some --arguments`
    argument_command="cmd_1",
)

augray avatar Sep 26 '22 21:09 augray

What if you want to run 3 commands and only first and third need these arguments? :)

IIRC each command can have individual arguments for such use cases.

ash2k avatar Sep 26 '22 21:09 ash2k

You could make argument_command a list called invocation_argument_commands:

multirun(
    name = "bar",
    commands = [
        "cmd_1",
        "cmd_2",
        "cmd_3",
    ],
    
    # when doing `bazel run //foo:bar -- --some --arguments`
    # only cmd_1 & cmd_3 should see `--some --arguments`
    invocation_argument_commands=["cmd_1", "cmd_3"]
)

though in practice it feels that only one of the commands will typically be desired as the place to put the args from the actual invocation. Regarding the commands having individual arguments, that seems to be workable if you know the arguments before somebody calls bazel run, but if you want them to be overridable for one (or more) of your commands at invocation time it works less well.

augray avatar Sep 26 '22 21:09 augray

FWIW, my use case is that I want to run a command for pushing a docker image and then execute a script that uses that pushed image. The script is one that people will be running regularly, and wanting to change the arguments at bazel run time.

augray avatar Sep 26 '22 21:09 augray

@augray why not create "intermediary" commands? use command macro to create a command with all the required arguments and then use those "intermediary" commands in multirun?

ramilmsh avatar Jan 06 '23 14:01 ramilmsh