Hi! Every time someone calls `pants run`, I want d...
# general
b
Hi! Every time someone calls
pants run
, I want do add flag:
--filter-address-regex='.*@resolve=XXX'
. I imagine there's some way to do this in
pants.toml
? In particular, can
XXX
be an environment variable? Essentially, I want to specify that when I call
pants run path/to/my:file
it should call
pants run path/to/my:file@resolve=XXX
, were
XXX
is set according to some environment variable (or some other mechanism)
c
you can have an alias, so:
Copy code
[cli.alias]
resolve-filter = "--filter-address-regex='.*@resolve=%(env.XXX)s'"
and then the invocation could include that:
Copy code
pants run resolve-filter path/to/some:file
if you want the filter to always be set, you could set that in the config too:
Copy code
[filter]
address_regex = ["..."]
if you’re on pants >=2.19 your alias may also begin with hyphens to make flag like aliases more intuitive.. so could be:
Copy code
[cli-alias]
--resolve-filter = ...
b
Awesome! This is exactly what I was looking for 🙂
One more thing: is there a way to specify a default variable if the env var is empty?
Something like docker compose: ${VAR_NAME:-default}
c
I’m not aware of that for the syntax used in the
pants.toml
file.. but you could have a
.pants.bootstrap
file, which is basically a shell script, and it could do:
Copy code
: ${VAR_NAME:=default}
export VAR_NAME
that way you’re guaranteed to always have a value for it…
b
Forgot to reply: thanks, I ended up going with the easy solution 🙂
👍 1
b
@curved-television-6568 this is very useful functionality without any reference in the docs (unless I missed it..)
👍 2