Skip to content

Commit 7494e5c

Browse files
committed
doc updates
1 parent 176652a commit 7494e5c

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ Installation
9191
'django_typer',
9292
]
9393
94+
*You only need to install django_typer as an app if you want to use the shellcompletion command
95+
to enable tab-completion or if you would like django-typer to install `rich traceback rendering
96+
<https://django-typer.readthedocs.io/en/latest/howto.html#configure-rich-stack-traces>`_
97+
for you - which it does by default if rich is also installed.*
9498

9599
Basic Example
96100
-------------
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django_typer import TyperCommand, command
2+
from django_typer import initialize as root
3+
4+
5+
class Command(TyperCommand):
6+
7+
@root(invoke_without_command=True)
8+
def handle(self, flag: bool = False):
9+
# This is the root command, it runs when we run our command without
10+
# any subcommand
11+
print(flag)
12+
13+
@command()
14+
def subcommand1(self):
15+
pass
16+
17+
@command()
18+
def subcommand2(self):
19+
pass

doc/source/howto.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,27 @@ pass these options upstream to Typer_ by supplying them as keyword arguments to
348348
is undefined.
349349

350350

351-
Define Shell Completions for Parameter values
352-
----------------------------------------------
351+
Define Shell Tab Completions for Parameters
352+
-------------------------------------------
353353

354354
See the section on :ref:`defining shell completions.<define-shellcompletions>`
355355

356356

357+
Debug Shell Tab Completers
358+
--------------------------
359+
360+
See the section on :ref:`debugging shell completers.<debug-shellcompletions>`
361+
362+
363+
Extend/Override TyperCommands
364+
-----------------------------
365+
366+
You can extend typer commands simply by subclassing them. All of the normal inheritance rules
367+
apply. You can either subclass an existing command from an upstream app and leave its module the
368+
same name to extend and override the command or you can subclass and rename the module to provide
369+
an adapted version of the upstream command with a different name.
370+
371+
357372
.. _configure-rich-exception-tracebacks:
358373

359374
Configure rich_ Stack Traces

doc/source/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ BaseCommand functionality is preserved, so that TyperCommand can be a drop in re
4949
'django_typer',
5050
]
5151
52+
*You only need to install django_typer as an app if you want to use the shellcompletion command
53+
to enable tab-completion or if you would like django-typer to install*
54+
:ref:`rich traceback rendering <configure-rich-exception-tracebacks>` *for you - which it does by
55+
default if rich is also installed.*
5256

5357
:big:`Basic Example`
5458

doc/source/shell_completion.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,23 @@ Django_ app labels like this:
211211

212212
See the :class:`~django_typer.completers.ModelObjectCompleter` for a completer that works
213213
for many Django_ model field types.
214+
215+
216+
.. _debug-shellcompletions:
217+
218+
Debugging Tab Completers
219+
========================
220+
221+
Debugging tab completion code can be tricky because when invoked in situ in the shell the completer
222+
code is run as a subprocess and it's output is captured by the shell. This means you can't set a
223+
breakpoint and enter into the debugger easily.
224+
225+
To help with this django-typer_ provides a debug mode that will enter into the tab-completion logic
226+
flow. Use the :class:`shellcompletion <django_typer.management.commands.shellcompletion.Command>`
227+
:func:`~django_typer.management.commands.shellcompletion.Command.complete` command, to pass the
228+
command line string that you would like to debug. For example:
229+
230+
.. code-block:: bash
231+
232+
./manage.py shellcompletion complete "mycommand --"
233+

0 commit comments

Comments
 (0)