https://pantsbuild.org/ logo
#general
Title
# general
h

high-energy-55500

09/16/2022, 12:58 PM
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

bitter-ability-32190

09/16/2022, 1:23 PM
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

high-energy-55500

09/16/2022, 1:32 PM
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

bitter-ability-32190

09/16/2022, 2:09 PM
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

high-energy-55500

09/16/2022, 2:10 PM
b

bitter-ability-32190

09/16/2022, 2:17 PM
If you're interested in contributing, we're happy to help you along
h

high-energy-55500

09/16/2022, 3:56 PM
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

witty-crayon-22786

09/16/2022, 5:15 PM
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

high-energy-55500

09/16/2022, 5:16 PM
seems to be a bug in 2.12 then
unless i’m doing something stupid
w

witty-crayon-22786

09/16/2022, 5:17 PM
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
5 Views