question regarding `experimental_shell_command`s: ...
# general
h
question regarding `experimental_shell_command`s: is it possible to pass in arguments when calling
./pants run
on a shell command? the docs recommend the following template:
Copy code
experimental_shell_command(
    name="my-script",
    command="./my-script.sh --flag",
    dependencies=[":scripts"],
)
which i can the call with e.g.
./pants run src:my-script
. but the
command
here appears to be static, what if I wanted to pass in a variable?
./pants run src:my-script -- foo
doesn’t seem to work
b
So the usefulness of that target is to act like a "codegenator" in the larger context of your build (note the "outputs" field). If you just want to run a shell script, there's it's cousin
experimental_run_shell_command
There's also an open request to just
run
a shell_source
👍 1
h
ah, i misquoted the docs, I’m actually using the
experimental_run_shell_command
you mentioned. I take it it’s not possible to pass in arbitrary arguments then? just tried
Copy code
command="./my-script.sh --flag {1}",
and i get an index error when running
./pants run src:my-script -- foo
b
I'm sure it's possible but I'd have to check the code. However I think the "run a source" feature would make this work and just replace that `run_shell`target
👍 1
h
b
If you're interested in contributing, we're happy to help you along
h
I am, and I’ve been meaning to get around to contributing on another ticket: https://github.com/pantsbuild/pants/issues/15630 once that’s done i’d be more than happy to pick this one up as well 🙂
w
regardless of “run a source” vs “run a target”, this is known as “passthrough args”:
run
appends the args after
--
to the command that it invokes, so
./pants run $target -- foo
should work without any modification to the target itself. if it doesn’t, it’s a bug in the
shell
run
implementation
h
seems to be a bug in 2.12 then
unless i’m doing something stupid
w
so it looks like the issue is that that will append args onto something like
bash -c $script
… which won’t actually result in them making it to your script as args.
opened https://github.com/pantsbuild/pants/issues/16901 about this: should be straightforward to fix!
🚀 1
❤️ 1