Skip to content

Commit

Permalink
DynamicEntryPointCommandGroup: Pass ctx to command callable
Browse files Browse the repository at this point in the history
This will allow the `command` callable to access things like the loaded
config and profile through `ctx.obj.config` and `ctx.obj.profile`,
respectively.
  • Loading branch information
sphuber committed May 17, 2023
1 parent c72a252 commit 7de711b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def verdi_code():
"""Setup and manage codes."""


def create_code(cls, non_interactive, **kwargs): # pylint: disable=unused-argument
def create_code(ctx: click.Context, cls, non_interactive: bool, **kwargs): # pylint: disable=unused-argument
"""Create a new `Code` instance."""
try:
instance = cls(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions aiida/cmdline/groups/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def get_command(self, ctx, cmd_name):
:returns: The :class:`click.Command`.
"""
try:
command = self.create_command(cmd_name)
command = self.create_command(ctx, cmd_name)
except exceptions.EntryPointError:
command = super().get_command(ctx, cmd_name)
return command

def create_command(self, entry_point):
def create_command(self, ctx, entry_point):
"""Create a subcommand for the given ``entry_point``."""
cls = self.factory(entry_point)
command = functools.partial(self.command, cls)
command = functools.partial(self.command, ctx, cls)
command.__doc__ = cls.__doc__
return click.command(entry_point)(self.create_options(entry_point)(command))

Expand Down

0 comments on commit 7de711b

Please sign in to comment.