add command_class and group_class to Group
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent dee49e5 · Browse files · 1 file·+46 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+46 added−6 removed
- other:+46 added−6 removed
Provenance
- Commit
c465912- Tree
efdd14e- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
dee49e5
1 file changed+46 added−6 removed
modified:src/click/core.py+46 added-6 removed
1391 unmodified lines1392 1393 :param commands: a dictionary of commands.1394 """1395 1396+ #: If set, this is used by the group's :meth:`command` decorator1397+ #: as the default :class:`Command` class. This is useful to make all1398+ #: subcommands use a custom command class.1399+ #:1400+ #: .. versionadded:: 8.01401+ command_class = None1402+1403+ #: If set, this is used by the group's :meth:`group` decorator1404+ #: as the default :class:`Group` class. This is useful to make all1405+ #: subgroups use a custom group class.1406+ #:1407+ #: If set to the special value :class:`type` (literally1408+ #: ``group_class = type``), this group's class will be used as the1409+ #: default class. This makes a custom group class continue to make1410+ #: custom groups.1411+ #:1412+ #: .. versionadded:: 8.01413+ group_class = None1414+1415 def __init__(self, name=None, commands=None, **attrs):1416 super().__init__(name, **attrs)1417 #: the registered subcommands by their exported names.1418 self.commands = commands or {}9 unmodified lines1428 self.commands[name] = cmd1429 1430 def command(self, *args, **kwargs):1431 """A shortcut decorator for declaring and attaching a command to1413- the group. This takes the same arguments as :func:`command` but1414- immediately registers the created command with this instance by1415- calling into :meth:`add_command`.1432+ the group. This takes the same arguments as :func:`command` and1433+ immediately registers the created command with this group by1434+ calling :meth:`add_command`.1435+1436+ To customize the command class used, set the1437+ :attr:`command_class` attribute.1438+1439+ .. versionchanged:: 8.01440+ Added the :attr:`command_class` attribute.1441 """1442 from .decorators import command1443 1444+ if self.command_class is not None and "cls" not in kwargs:1445+ kwargs["cls"] = self.command_class1446+1447 def decorator(f):1448 cmd = command(*args, **kwargs)(f)1449 self.add_command(cmd)1450 return cmd1 unmodified line1452 return decorator1453 1454 def group(self, *args, **kwargs):1455 """A shortcut decorator for declaring and attaching a group to1428- the group. This takes the same arguments as :func:`group` but1429- immediately registers the created command with this instance by1430- calling into :meth:`add_command`.1456+ the group. This takes the same arguments as :func:`group` and1457+ immediately registers the created group with this group by1458+ calling :meth:`add_command`.1459+1460+ To customize the group class used, set the :attr:`group_class`1461+ attribute.1462+1463+ .. versionchanged:: 8.01464+ Added the :attr:`group_class` attribute.1465 """1466 from .decorators import group1467 1468+ if self.group_class is not None and "cls" not in kwargs:1469+ if self.group_class is type:1470+ kwargs["cls"] = type(self)1471+ else:1472+ kwargs["cls"] = self.group_class1473+1474 def decorator(f):1475 cmd = group(*args, **kwargs)(f)1476 self.add_command(cmd)1477 return cmd692 unmodified lines