Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pex3 lock sync. #2373

Merged
merged 18 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion pex/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from contextlib import contextmanager

from pex.commands.command import Command
from pex.result import Result
from pex.result import Error, Result
from pex.typing import TYPE_CHECKING, Generic, cast

if TYPE_CHECKING:
Expand All @@ -35,11 +35,23 @@ def parser(
help, # type: str
func=None, # type: Optional[Callable[[_C], Result]]
include_verbosity=None, # type: Optional[bool]
passthrough_args=None, # type: Optional[str]
):
# type: (...) -> Iterator[ArgumentParser]
subcommand_parser = self._subparsers.add_parser(name=name, help=help)
yield subcommand_parser
if func:
if passthrough_args:
# N.B.: This is a dummy arg for usage string display purposes; thus the "_" name.
subcommand_parser.add_argument(
"_", metavar="-- passthrough args", nargs="*", help=passthrough_args
)
else:
func = functools.partial(
BuildTimeCommand._check_no_passthrough_args_and_run,
subcommand_name=name,
subcommand_func=func,
)
subcommand_parser.set_defaults(subcommand_func=func)
Command.register_global_arguments(
subcommand_parser,
Expand Down Expand Up @@ -75,6 +87,20 @@ def create_subcommands(
subparsers = parser.add_subparsers(description=description)
return cls.Subcommands(subparsers, include_verbosity=cls.include_global_verbosity_option)

def _check_no_passthrough_args_and_run(
self,
subcommand_name, # type: str
subcommand_func, # type: Callable[[BuildTimeCommand], Result]
):
# type: (...) -> Result
if self.passthrough_args is not None:
return Error(
"The {subcommand} {command} subcommand does not accept pass through args.".format(
subcommand=subcommand_name, command=self.name()
)
)
return subcommand_func(self)

def run(self):
# type: (_C) -> Result
subcommand_func = cast(
Expand Down
Loading