Skip to content

Commit

Permalink
Track consumption of command-line args in the rust parser. (pantsbuil…
Browse files Browse the repository at this point in the history
…d#21410)

So we can error if unrecognized args are found.

This is a current feature of the legacy parser, so this is needed for
compatibility.
  • Loading branch information
benjyw authored Sep 16, 2024
1 parent 78f543a commit 69255bd
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/python/pants/engine/internals/native_engine.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class PyOptionParser:
) -> OptionListValue[str]: ...
def get_dict(self, option_id: PyOptionId, default: dict[str, Any]) -> OptionDictValue: ...
def get_passthrough_args(self) -> Optional[list[str]]: ...
def get_unconsumed_flags(self) -> list[str]: ...

# ------------------------------------------------------------------------------
# Testutil
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/option/native_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ def is_enum(typ):
val = option_type(val)

return (val, rank)

def get_unconsumed_flags(self) -> tuple[str, ...]:
return tuple(self._native_parser.get_unconsumed_flags())
5 changes: 4 additions & 1 deletion src/python/pants/option/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def _create_flag_value_map(flags: Iterable[str]) -> DefaultDict[str, list[str |
flag_value_map[key].append(flag_val)
return flag_value_map

def parse_args_native(self, native_parser: NativeOptionParser) -> OptionValueContainer:
def parse_args_native(
self,
native_parser: NativeOptionParser,
) -> OptionValueContainer:
namespace = OptionValueContainerBuilder()
for args, kwargs in self._option_registrations:
self._validate(args, kwargs)
Expand Down
57 changes: 29 additions & 28 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ whoami = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
parking_lot = "0.12.3"

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
Loading

0 comments on commit 69255bd

Please sign in to comment.