@@ -268,10 +268,10 @@ decorator. This is like defining a group at the command root and is an extension
268268Collect Results with @finalize
269269------------------------------
270270
271- Typer _ and Click _ have a ``results_callback `` mechanism on ``MultiCommands `` that allow a function
272- hook to be registered to operate on the results of subroutines before the command exits. You may
273- use this same ``results_callback `` mechanism directly through the Typer _ interface, but
274- django-typer _ offers a more convenient class-aware way to do this with the
271+ Typer _ and :doc: ` Click < click:index >` have a ``results_callback `` mechanism on ``MultiCommands ``
272+ that allow a function hook to be registered to operate on the results of subroutines before the
273+ command exits. You may use this same ``results_callback `` mechanism directly through the Typer _
274+ interface, but django-typer _ offers a more convenient class-aware way to do this with the
275275:func: `~django_typer.management.finalize ` decorator.
276276
277277For example lets say we have two subcommands that return strings, we could turn them into a csv
@@ -334,17 +334,19 @@ finalizers at higher levels in the command hierarchy.
334334
335335 .. tip ::
336336
337- Finalizers can be overridden just like groups and initializers using the :ref: `plugin pattern. <plugins >`
337+ Finalizers can be overridden just like groups and initializers using the
338+ :ref: `plugin pattern. <plugins >`
338339
339340
340341Call Commands from Code
341342-----------------------
342343
343344There are two options for invoking a :class: `~django_typer.management.TyperCommand ` from code
344- without spawning off a subprocess. The first is to use Django _'s builtin call_command _ function.
345- This function will work exactly as it does for normal BaseCommand _ derived commands. django-typer _
346- however adds another mechanism that can be more efficient, especially if your options and
347- arguments are already of the correct type and require no parsing:
345+ without spawning off a subprocess. The first is to use Django _'s builtin
346+ :func: `~django.core.management.call_command ` function. This function will work exactly as it does
347+ for normal :class: `~django.core.management.BaseCommand ` derived commands. django-typer _ however adds
348+ another mechanism that can be more efficient, especially if your options and arguments are already
349+ of the correct type and require no parsing:
348350
349351Say we have this command, called ``mycommand ``:
350352
@@ -378,7 +380,7 @@ Say we have this command, called ``mycommand``:
378380
379381 The rule of thumb is this:
380382
381- - Use call_command _ if your options and arguments need parsing.
383+ - Use :func: ` ~django.core.management.call_command ` if your options and arguments need parsing.
382384 - Use :func: `~django_typer.management.get_command ` and invoke the command functions directly if
383385 your options and arguments are already of the correct type.
384386
@@ -411,15 +413,16 @@ You may also fetch a subcommand function directly by passing its path:
411413Change Default Django Options
412414-----------------------------
413415
414- :class: `~django_typer.management.TyperCommand ` classes preserve all of the functionality of BaseCommand _ derivatives.
415- This means that you can still use class members like ` suppressed_base_arguments
416- <https://docs.djangoproject.com/en/5.0/howto/custom-management-commands/# django.core.management.BaseCommand.suppressed_base_arguments> `_
417- to suppress default options.
416+ :class: `~django_typer.management.TyperCommand ` classes preserve all of the functionality of
417+ :class: ` ~django.core.management.BaseCommand ` derivatives. This means that you can still use class
418+ members like :attr: ` ~ django.core.management.BaseCommand.suppressed_base_arguments` to suppress
419+ default options.
418420
419- By default :class: `~django_typer.management.TyperCommand ` suppresses ``--verbosity ``. You can add
420- it back by setting ``suppressed_base_arguments `` to an empty list. If you want to use verbosity you
421- can simply redefine it or use one of django-typer _'s :ref: `provided type hints <types >` for the
422- default BaseCommand _ options:
421+ By default :class: `~django_typer.management.TyperCommand ` suppresses :option: `--verbosity `. You can
422+ add it back by setting :attr: `~django.core.management.BaseCommand.suppressed_base_arguments ` to an
423+ empty list. If you want to use verbosity you can simply redefine it or use one of django-typer _'s
424+ :ref: `provided type hints <types >` for the default :class: `~django.core.management.BaseCommand `
425+ options:
423426
424427.. tabs ::
425428
@@ -631,28 +634,30 @@ and if it is not provided the function will be treated as a
631634
632635.. note ::
633636
634- **Conflicting extensions are resolved in INSTALLED_APPS order. ** For a detailed discussion
635- about the utility of this pattern, see the tutorial on :ref: `Extending Commands <plugins >`.
637+ **Conflicting extensions are resolved in ** :setting: `INSTALLED_APPS ` **order. ** For a detailed
638+ discussion about the utility of this pattern, see the tutorial on
639+ :ref: `Extending Commands <plugins >`.
636640
637641.. warning ::
638642
639643 Take care not to import any extension code during or before Django's bootstrap procedure. This
640- may result in conflict override behavior that does not honor INSTALLED_APPS order.
644+ may result in conflict override behavior that does not honor :setting: ` INSTALLED_APPS ` order.
641645
642646.. _configure-rich-exception-tracebacks :
643647
644- Configure rich _ Stack Traces
645- ----------------------------
648+ Configure :doc: ` rich < rich:index >` Stack Traces
649+ -----------------------------------------------
646650
647- When rich _ is installed it may be ` configured to display rendered stack traces
648- <https:// rich.readthedocs.io/en/stable/ traceback.html> `_ for unhandled exceptions.
651+ When :doc: ` rich < rich:index >` is installed it may be
652+ :doc: ` configured to display rendered stack traces < rich: traceback >` for unhandled exceptions.
649653These stack traces are information dense and can be very helpful for debugging. By default, if
650- rich _ is installed django-typer _ will configure it to render stack traces. You can disable
651- this behavior by setting the ``DT_RICH_TRACEBACK_CONFIG `` config to ``False ``. You may also
652- set ``DT_RICH_TRACEBACK_CONFIG `` to a dictionary holding the parameters to pass to
653- `rich.traceback.install `.
654+ :doc: ` rich < rich:index >` is installed django-typer _ will configure it to render stack traces. You
655+ can disable this behavior by setting the ``DT_RICH_TRACEBACK_CONFIG `` config to ``False ``. You may
656+ also set ``DT_RICH_TRACEBACK_CONFIG `` to a dictionary holding the parameters to pass to
657+ :func: `rich.traceback.install `.
654658
655- This provides a common hook for configuring rich _ that you can control on a per-deployment basis:
659+ This provides a common hook for configuring :doc: `rich <rich:index >` that you can control on a
660+ per-deployment basis:
656661
657662.. code-block ::
658663 :caption: settings.py
@@ -819,22 +824,21 @@ print, self.stdout and typer.echo
819824---------------------------------
820825
821826There are no unbreakable rules about how you should print output from your commands.
822- You could use loggers, normal print statements or the BaseCommand _ stdout and
823- stderr output wrappers. Django advises the use of ``self.stdout.write `` because the
824- stdout and stderr streams can be configured by calls to call_command _ or
825- :func: `~django_typer.management.get_command ` which allows you to easily grab output from your
826- commands for testing. Using the command's configured stdout and stderr
827- output wrappers also means output will respect the ``--force-color `` and ``--no-color ``
828- parameters.
829-
830- Typer _ and click _ provide `echo and secho <https://typer.tiangolo.com/tutorial/printing/ >`_
831- functions that automatically handle byte to string conversions and offer simple styling
832- support. :class: `~django_typer.management.TyperCommand ` provides
833- :meth: `~django_typer.management.TyperCommand.echo ` and
827+ You could use loggers, normal print statements or the :class: `~django.core.management.BaseCommand `
828+ stdout and stderr output wrappers. Django advises the use of ``self.stdout.write `` because the
829+ stdout and stderr streams can be configured by calls to :func: `~django.core.management.call_command `
830+ or :func: `~django_typer.management.get_command ` which allows you to easily grab output from your
831+ commands for testing. Using the command's configured stdout and stderr output wrappers also means
832+ output will respect the :option: `--force-color ` and :option: `--no-color ` parameters.
833+
834+ Typer _ and :doc: `click <click:index >` provide `echo and secho
835+ <https://typer.tiangolo.com/tutorial/printing/> `_ functions that automatically handle byte to string
836+ conversions and offer simple styling support. :class: `~django_typer.management.TyperCommand `
837+ provides :meth: `~django_typer.management.TyperCommand.echo ` and
834838:meth: `~django_typer.management.TyperCommand.secho ` wrapper functions for the Typer _ echo/secho
835839functions. If you wish to use Typer _'s echo you should use these wrapper functions because they
836- honor the command's `` --force-color `` and `` --no-color `` flags and the configured stdout/stderr
837- streams:
840+ honor the command's :option: ` --force-color ` and :option: ` --no-color ` flags and the configured
841+ stdout/stderr streams:
838842
839843.. tabs ::
840844
@@ -854,9 +858,10 @@ streams:
854858Toggle on/off result printing
855859-----------------------------
856860
857- Django's BaseCommand _ will print any truthy values returned from the handle() method. This may not
858- always be desired behavior. By default :class: `~django_typer.management.TyperCommand ` will do the
859- same, but you may toggle this behavior off by setting the class field ``print_result `` to False.
861+ Django's :class: `~django.core.management.BaseCommand ` will print any truthy values returned from the
862+ :meth: `~django.core.management.BaseCommand.handle ` method. This may not always be desired behavior.
863+ By default :class: `~django_typer.management.TyperCommand ` will do the same, but you may toggle this
864+ behavior off by setting the class field ``print_result `` to False.
860865
861866
862867.. tabs ::
0 commit comments