Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
e95008f2
Kaydet (Commit)
e95008f2
authored
Haz 11, 2018
tarafından
humbertotm
Kaydeden (comit)
Tim Graham
Haz 16, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29152 -- Allowed passing kwargs to ArgumentParser initialization in management commands.
üst
11bfe3a8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
base.py
django/core/management/base.py
+2
-1
custom-management-commands.txt
docs/howto/custom-management-commands.txt
+13
-0
tests.py
tests/user_commands/tests.py
+6
-0
No files found.
django/core/management/base.py
Dosyayı görüntüle @
e95008f2
...
...
@@ -244,7 +244,7 @@ class BaseCommand:
"""
return
django
.
get_version
()
def
create_parser
(
self
,
prog_name
,
subcommand
):
def
create_parser
(
self
,
prog_name
,
subcommand
,
**
kwargs
):
"""
Create and return the ``ArgumentParser`` which will be used to
parse the arguments to this command.
...
...
@@ -255,6 +255,7 @@ class BaseCommand:
formatter_class
=
DjangoHelpFormatter
,
missing_args_message
=
getattr
(
self
,
'missing_args_message'
,
None
),
called_from_command_line
=
getattr
(
self
,
'_called_from_command_line'
,
None
),
**
kwargs
)
parser
.
add_argument
(
'--version'
,
action
=
'version'
,
version
=
self
.
get_version
())
parser
.
add_argument
(
...
...
docs/howto/custom-management-commands.txt
Dosyayı görüntüle @
e95008f2
...
...
@@ -255,6 +255,19 @@ the :meth:`~BaseCommand.handle` method must be implemented.
super().__init__(*args, **kwargs)
# ...
.. method:: BaseCommand.create_parser(prog_name, subcommand, **kwargs)
Returns a ``CommandParser`` instance, which is an
:class:`~argparse.ArgumentParser` subclass with a few customizations for
Django.
You can customize the instance by overriding this method and calling
``super()`` with ``kwargs`` of :class:`~argparse.ArgumentParser` parameters.
.. versionchanged:: 2.2
``kwargs`` was added.
.. method:: BaseCommand.add_arguments(parser)
Entry point to add parser arguments to handle command line arguments passed
...
...
tests/user_commands/tests.py
Dosyayı görüntüle @
e95008f2
...
...
@@ -220,6 +220,12 @@ class CommandTests(SimpleTestCase):
with
self
.
assertRaisesMessage
(
CommandError
,
msg
):
management
.
call_command
(
'subparser'
,
'test'
,
12
)
def
test_create_parser_kwargs
(
self
):
"""BaseCommand.create_parser() passes kwargs to CommandParser."""
epilog
=
'some epilog text'
parser
=
BaseCommand
()
.
create_parser
(
'prog_name'
,
'subcommand'
,
epilog
=
epilog
)
self
.
assertEqual
(
parser
.
epilog
,
epilog
)
class
CommandRunTests
(
AdminScriptTestCase
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment