Skip to content

Commit

Permalink
Do not interpret passthrough args, which are already in the appropria…
Browse files Browse the repository at this point in the history
…te type for their container.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
  • Loading branch information
stuhood committed Mar 9, 2021
1 parent 3e7e97a commit 26a759c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/python/pants/option/options_test.py
Expand Up @@ -1048,6 +1048,27 @@ def test_at_most_one_goal_with_passthru_args(self):
"(args after `--`) is ambiguous."
) in str(exc.value)

def test_passthru_args_not_interpreted(self):
# Test that passthrough args are not interpreted.
options = Options.create(
env={},
config=self._create_config(),
known_scope_infos=[global_scope(), task("test"), subsystem("consumer")],
args=["./pants", "--consumer-shlexed=a", "--consumer-string=b", "test", "--", "[bar]"],
)
options.register(
"consumer", "--shlexed", passthrough=True, type=list, member_type=shell_str
)
options.register("consumer", "--string", passthrough=True, type=list, member_type=str)
self.assertEqual(
["a", "[bar]"],
options.for_scope("consumer").shlexed,
)
self.assertEqual(
["b", "[bar]"],
options.for_scope("consumer").string,
)

def test_global_scope_env_vars(self):
def check_pants_foo(expected_val, env):
val = self._parse(env=env).for_global_scope().pants_foo
Expand Down
8 changes: 7 additions & 1 deletion src/python/pants/option/parser.py
Expand Up @@ -661,7 +661,13 @@ def expand(val_or_str):
# Get value from cmd-line flags.
flag_vals = [to_value_type(expand(x)) for x in flag_val_strs]
if kwargs.get("passthrough"):
flag_vals.extend(to_value_type(x) for x in passthru_arg_strs)
# NB: Passthrough arguments are either of type `str` or `shell_str`
# (see self._validate): the former never need interpretation, and the latter do not
# need interpretation when they have been provided directly via `sys.argv` as the
# passthrough args have been.
flag_vals.append(
ListValueComponent(ListValueComponent.MODIFY, [*passthru_arg_strs], [])
)

if is_list_option(kwargs):
# Note: It's important to set flag_val to None if no flags were specified, so we can
Expand Down

0 comments on commit 26a759c

Please sign in to comment.