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

Minimize boilerplate when building Commands/Options #4292

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use null object instead of string sentinel
nwatson22 committed May 7, 2024
commit 4ade3ff8db2389f2fbc449ac2a648c16d4813e16
6 changes: 4 additions & 2 deletions pyk/src/pyk/cli/cli.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@

_LOGGER: Final = logging.getLogger(__name__)

NO_DEFAULT: Final = object()


class CLI:
_commands: list[Command]
@@ -46,7 +48,7 @@ def get_command(self, args: dict[str, Any]) -> Command:
def get_and_exec_command(self) -> None:
parser = self.create_argument_parser()
args = parser.parse_args()
stripped_args = {key: val for (key, val) in vars(args).items() if val != 'NoDefault'}
stripped_args = {key: val for (key, val) in vars(args).items() if val != NO_DEFAULT}
cmd = self.get_command(stripped_args)
cmd._options_group.extract(stripped_args, cmd.name)
cmd.exec()
@@ -77,7 +79,7 @@ def __init__(
choices: list[str] | None = None,
const: Any | None = None,
aliases: Iterable[str] = (),
default: Any | str = 'NoDefault',
default: Any | str = NO_DEFAULT,
metavar: str | None = None,
nargs: int | str | None = None,
required: bool = False,