Skip to content

Commit 8641896

Browse files
committed
more howto doc works
1 parent 17fd306 commit 8641896

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1315
-625
lines changed

backup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
django_typer/tests/backup.py

django_typer/__init__.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
)
127127
from .utils import (
128128
_command_context,
129-
_load_command_extensions,
129+
_load_command_plugins,
130130
called_from_command_definition,
131131
called_from_module,
132132
get_usage_script,
@@ -861,6 +861,50 @@ class Typer(typer.Typer, t.Generic[P, R], metaclass=AppFactory):
861861
Typer_ apps. This class extends the ``typer.Typer`` class so that we can add
862862
the additional information necessary to attach this app to the root app
863863
and other groups specified on the django command.
864+
865+
:param name: the name of the class being created
866+
:param bases: the base classes of the class being created
867+
:param attrs: the attributes of the class being created
868+
:param cls: The class to use as the core typer group wrapper
869+
:param invoke_without_command: whether to invoke the group callback if no command
870+
was specified.
871+
:param no_args_is_help: whether to show the help if no arguments are provided
872+
:param subcommand_metavar: the metavar to use for subcommands in the help output
873+
:param chain: whether to chain commands, this allows multiple commands from the group
874+
to be specified and run in order sequentially in one call from the command line.
875+
:param result_callback: a callback to invoke with the result of the command
876+
:param context_settings: the click context settings to use - see
877+
`click docs <https://click.palletsprojects.com/api/#context>`_.
878+
:param help: the help string to use, defaults to the function docstring, if you need
879+
to translate the help you should use the help kwarg instead because docstrings
880+
will not be translated.
881+
:param epilog: the epilog to use in the help output
882+
:param short_help: the short help to use in the help output
883+
:param options_metavar: the metavar to use for options in the help output
884+
:param add_help_option: whether to add the help option to the command
885+
:param hidden: whether to hide this group from the help output
886+
:param deprecated: show a deprecation warning
887+
:param rich_markup_mode: the rich markup mode to use - if rich is installed
888+
this can be used to enable rich markup or Markdown in the help output. Can
889+
be "markdown", "rich" or None to disable markup rendering.
890+
:param rich_help_panel: the rich help panel to use - if rich is installed
891+
this can be used to group commands into panels in the help output.
892+
:param pretty_exceptions_enable: whether to enable pretty exceptions - if rich is
893+
installed this can be used to enable pretty exception rendering. This will
894+
default to on if the traceback configuration settings installs the rich
895+
traceback handler. This allows tracebacks to be configured by the user on a
896+
per deployment basis in the settings file. We therefore do not advise
897+
hardcoding this value.
898+
:param pretty_exceptions_show_locals: whether to show local variables in pretty
899+
exceptions - if rich is installed. This will default to the 'show_locals'
900+
setting in the traceback configuration setting (on by default). This allows
901+
tracebacks to be configured by the user on a per deployment basis in the
902+
settings file. We therefore do not advise hardcoding this value.
903+
:param pretty_exceptions_short: whether to show short tracebacks in pretty
904+
exceptions - if rich is installed. This will default to the 'short' setting
905+
in the traceback configuration setting (off by default). This allows tracebacks
906+
to be configured by the user on a per deployment basis in the settings file. We
907+
therefore do not advise hardcoding this value.
864908
"""
865909

866910
parent: t.Optional["Typer"] = None
@@ -1727,12 +1771,9 @@ def _resolve_help(dj_cmd: "TyperCommand"):
17271771
"""
17281772
hlp = None
17291773
for cmd_cls in [
1730-
dj_cmd.__class__,
1731-
*[
1732-
c
1733-
for c in dj_cmd.__class__.__mro__
1734-
if issubclass(c, TyperCommand) and c is not TyperCommand
1735-
],
1774+
c
1775+
for c in dj_cmd.__class__.__mro__
1776+
if issubclass(c, TyperCommand) and c is not TyperCommand
17361777
]:
17371778
hlp = cmd_cls.__doc__
17381779
if hlp:
@@ -2896,7 +2937,7 @@ def __init__(
28962937
**kwargs,
28972938
):
28982939
assert self.typer_app.info.name
2899-
_load_command_extensions(self.typer_app.info.name)
2940+
_load_command_plugins(self.typer_app.info.name)
29002941
_add_common_initializer(self)
29012942
_resolve_help(self)
29022943

django_typer/tests/apps/adapter0/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.apps import AppConfig
2-
from django_typer.utils import register_command_extensions
2+
from django_typer.utils import register_command_plugins
33

44

55
class Adapter1Config(AppConfig):
@@ -10,4 +10,4 @@ class Adapter1Config(AppConfig):
1010
def ready(self):
1111
from .management import adapters
1212

13-
register_command_extensions(adapters)
13+
register_command_plugins(adapters)

django_typer/tests/apps/adapter1/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.apps import AppConfig
2-
from django_typer.utils import register_command_extensions
2+
from django_typer.utils import register_command_plugins
33

44

55
class Adapter1Config(AppConfig):
@@ -10,4 +10,4 @@ class Adapter1Config(AppConfig):
1010
def ready(self):
1111
from .management import adapters
1212

13-
register_command_extensions(adapters)
13+
register_command_plugins(adapters)

django_typer/tests/apps/adapter2/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.apps import AppConfig
2-
from django_typer.utils import register_command_extensions
2+
from django_typer.utils import register_command_plugins
33

44

55
class Adapter2Config(AppConfig):
@@ -10,4 +10,4 @@ class Adapter2Config(AppConfig):
1010
def ready(self):
1111
from .management import adapters
1212

13-
register_command_extensions(adapters, ["adapted2"])
13+
register_command_plugins(adapters, ["adapted2"])

django_typer/tests/apps/howto/apps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.apps import AppConfig
2+
from django_typer.utils import register_command_plugins
3+
4+
5+
class HowtoApp(AppConfig):
6+
name = "django_typer.tests.apps.howto"
7+
label = name.replace(".", "_")
8+
9+
def ready(self):
10+
from .management import plugins
11+
12+
register_command_plugins(plugins)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django_typer import TyperCommand, command
2+
3+
4+
# here we pass chain=True to typer telling it to allow invocation of
5+
# multiple subcommands
6+
class Command(TyperCommand, chain=True):
7+
@command()
8+
def cmd1(self):
9+
self.stdout.write("cmd1")
10+
11+
@command()
12+
def cmd2(self):
13+
self.stdout.write("cmd2")

0 commit comments

Comments
 (0)