summaryrefslogtreecommitdiff
path: root/cmd2/command_definition.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r--cmd2/command_definition.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index c85814d7..e319d7f3 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -17,11 +17,14 @@ from .exceptions import (
# Allows IDEs to resolve types without impacting imports at runtime, breaking circular dependency issues
try: # pragma: no cover
- from typing import TYPE_CHECKING
+ from typing import (
+ TYPE_CHECKING,
+ )
+
if TYPE_CHECKING:
import cmd2
-except ImportError: # pragma: no cover
+except ImportError: # pragma: no cover
pass
@@ -48,22 +51,31 @@ def with_default_category(category: str, *, heritable: bool = True):
if heritable:
setattr(cls, CLASS_ATTR_DEFAULT_HELP_CATEGORY, category)
- from .constants import CMD_ATTR_HELP_CATEGORY
import inspect
- from .decorators import with_category
+
+ from .constants import (
+ CMD_ATTR_HELP_CATEGORY,
+ )
+ from .decorators import (
+ with_category,
+ )
+
# get members of the class that meet the following criteria:
# 1. Must be a function
# 2. Must start with COMMAND_FUNC_PREFIX (do_)
# 3. Must be a member of the class being decorated and not one inherited from a parent declaration
methods = inspect.getmembers(
cls,
- predicate=lambda meth: inspect.isfunction(meth) and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
- and meth in inspect.getmro(cls)[0].__dict__.values())
+ predicate=lambda meth: inspect.isfunction(meth)
+ and meth.__name__.startswith(COMMAND_FUNC_PREFIX)
+ and meth in inspect.getmro(cls)[0].__dict__.values(),
+ )
category_decorator = with_category(category)
for method in methods:
if not hasattr(method[1], CMD_ATTR_HELP_CATEGORY):
setattr(cls, method[0], category_decorator(method[1]))
return cls
+
return decorate_class