@@ -54,58 +54,73 @@ replacement.
54
54
55
55
*You only need to install django_typer as an app if you want to use the shellcompletion command
56
56
to enable tab-completion or if you would like django-typer to install *
57
- :ref: `rich traceback rendering <configure-rich-exception-tracebacks >` *for you - which it does by
58
- default if rich is also installed. *
57
+ :ref: `rich traceback rendering <configure-rich-exception-tracebacks >` *for you - which it does
58
+ by default if rich is also installed. *
59
+
60
+ .. note ::
61
+
62
+ This documentation shows all examples using both the function orientied Typer-style interface
63
+ and the class based Django-style interface using tabs. Each interface is equivalent so the
64
+ choice of which to use is a matter of preference.
59
65
60
66
:big: `Basic Example `
61
67
62
68
For example TyperCommands can be a very simple drop in replacement for BaseCommands. All of the
63
- documented features of BaseCommand _ work!
69
+ documented features of BaseCommand _ work! Or, you may also use an interface identitical to Typer's.
70
+ Simply import Typer from django_typer instead of typer.
64
71
72
+ .. tabs ::
65
73
66
- .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/basic.py
67
- :language: python
68
- :caption: A Basic Command
69
- :linenos:
74
+ .. tab :: Django-style
70
75
71
- Or, you may also use an interface identitical to Typer's. Simply import Typer from django_typer
72
- instead of typer:
76
+ .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/basic.py
77
+ :language: python
78
+ :caption: management/commands/basic.py
79
+ :linenos:
73
80
74
- .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/basic.py
75
- :language: python
76
- :caption: A Typer-style Basic Command
77
- :linenos:
81
+ .. tab :: Typer-style
82
+
83
+ .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/basic.py
84
+ :language: python
85
+ :caption: management/commands/basic.py
86
+ :linenos:
78
87
79
88
80
89
.. typer :: django_typer.tests.apps.examples.basic.management.commands.basic.Command:typer_app
81
90
:prog: ./manage.py basic
82
91
:width: 80
83
92
:convert-png: latex
93
+ :theme: dark
84
94
85
95
|
86
96
87
97
:big: `Multiple Subcommands Example `
88
98
89
99
Commands with multiple subcommands can be defined:
90
100
91
- .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/multi.py
92
- :language: python
93
- :caption: A Command w/Subcommands
94
- :linenos:
101
+ .. tabs ::
102
+
103
+ .. tab :: Django-style
95
104
96
- Or using the typer-style interface this could be written:
105
+ .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/multi.py
106
+ :language: python
107
+ :caption: management/commands/multi.py
108
+ :linenos:
97
109
98
- .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/multi.py
99
- :language: python
100
- :caption: A Typer-style Command w/Subcommands
101
- :linenos:
110
+ .. tab :: Typer-style
111
+
112
+ .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/multi.py
113
+ :language: python
114
+ :caption: management/commands/multi.py
115
+ :linenos:
102
116
103
117
104
118
.. typer :: django_typer.tests.apps.examples.basic.management.commands.multi.Command:typer_app
105
119
:prog: ./manage.py multi
106
120
:width: 80
107
121
:show-nested:
108
122
:convert-png: latex
123
+ :theme: dark
109
124
110
125
|
111
126
@@ -124,29 +139,33 @@ command like so:
124
139
./manage.py hierarchy math multiply 10 2
125
140
20.00
126
141
127
- Any number of groups and subcommands and subgroups of other groups can be defined allowing
128
- for arbitrarily complex command hierarchies. Using the class-based interface we could define
129
- the command like this:
142
+ Any number of groups and subcommands and subgroups of other groups can be defined allowing for
143
+ arbitrarily complex command hierarchies. The Typer-style interface builds a TyperCommand class for
144
+ us. **This allows you to optionally accept the self argument in your commands. ** We could define
145
+ the above command using the typer interface like this:
146
+
147
+ .. tabs ::
148
+
149
+ .. tab :: Django-style
130
150
131
- .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/hierarchy.py
132
- :language: python
133
- :caption: A Command w/Grouping Hierarchy
134
- :linenos:
151
+ .. literalinclude :: ../../django_typer/tests/apps/examples/basic/management/commands/hierarchy.py
152
+ :language: python
153
+ :caption: management/commands/hierarchy.py
154
+ :linenos:
135
155
136
- The typer-style interface builds a TyperCommand class for us. This allows you to optionally
137
- accept the self argument in your commands. We could define the above command using the typer
138
- interface like this:
156
+ .. tab :: Typer-style
139
157
140
- .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/hierarchy.py
141
- :language: python
142
- :caption: A Typer-style Command w/Grouping Hierarchy
143
- :linenos:
158
+ .. literalinclude :: ../../django_typer/tests/apps/examples/typer/management/commands/hierarchy.py
159
+ :language: python
160
+ :caption: management/commands/hierarchy.py
161
+ :linenos:
144
162
145
163
.. typer :: django_typer.tests.apps.examples.basic.management.commands.hierarchy.Command:typer_app
146
164
:prog: ./manage.py hierarchy
147
165
:width: 80
148
166
:show-nested:
149
167
:convert-png: latex
168
+ :theme: dark
150
169
151
170
|
152
171
0 commit comments