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
dd68b51e
Kaydet (Commit)
dd68b51e
authored
Nis 21, 2018
tarafından
Hasan Ramezani
Kaydeden (comit)
Tim Graham
Nis 21, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29295 -- Fixed management command crash when using subparsers.
Thanks Tim Graham for the fix.
üst
21420096
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
7 deletions
+32
-7
__init__.py
django/core/management/__init__.py
+1
-1
base.py
django/core/management/base.py
+9
-6
subparser.py
tests/user_commands/management/commands/subparser.py
+12
-0
tests.py
tests/user_commands/tests.py
+10
-0
No files found.
django/core/management/__init__.py
Dosyayı görüntüle @
dd68b51e
...
...
@@ -311,7 +311,7 @@ class ManagementUtility:
# Preprocess options to extract --settings and --pythonpath.
# These options could affect the commands that are available, so they
# must be processed early.
parser
=
CommandParser
(
None
,
usage
=
"
%(prog)
s subcommand [options] [args]"
,
add_help
=
False
)
parser
=
CommandParser
(
usage
=
'
%(prog)
s subcommand [options] [args]'
,
add_help
=
False
)
parser
.
add_argument
(
'--settings'
)
parser
.
add_argument
(
'--pythonpath'
)
parser
.
add_argument
(
'args'
,
nargs
=
'*'
)
# catch-all
...
...
django/core/management/base.py
Dosyayı görüntüle @
dd68b51e
...
...
@@ -42,19 +42,20 @@ class CommandParser(ArgumentParser):
SystemExit in several occasions, as SystemExit is unacceptable when a
command is called programmatically.
"""
def
__init__
(
self
,
cmd
,
**
kwargs
):
self
.
cmd
=
cmd
def
__init__
(
self
,
**
kwargs
):
self
.
missing_args_message
=
kwargs
.
pop
(
'missing_args_message'
,
None
)
self
.
called_from_command_line
=
kwargs
.
pop
(
'called_from_command_line'
,
None
)
super
()
.
__init__
(
**
kwargs
)
def
parse_args
(
self
,
args
=
None
,
namespace
=
None
):
# Catch missing argument for a better error message
if
(
hasattr
(
self
.
cmd
,
'missing_args_message'
)
and
if
(
self
.
missing_args_message
and
not
(
args
or
any
(
not
arg
.
startswith
(
'-'
)
for
arg
in
args
))):
self
.
error
(
self
.
cmd
.
missing_args_message
)
self
.
error
(
self
.
missing_args_message
)
return
super
()
.
parse_args
(
args
,
namespace
)
def
error
(
self
,
message
):
if
self
.
c
md
.
_c
alled_from_command_line
:
if
self
.
called_from_command_line
:
super
()
.
error
(
message
)
else
:
raise
CommandError
(
"Error:
%
s"
%
message
)
...
...
@@ -225,8 +226,10 @@ class BaseCommand:
parse the arguments to this command.
"""
parser
=
CommandParser
(
self
,
prog
=
"
%
s
%
s"
%
(
os
.
path
.
basename
(
prog_name
),
subcommand
),
prog
=
'
%
s
%
s'
%
(
os
.
path
.
basename
(
prog_name
),
subcommand
),
description
=
self
.
help
or
None
,
missing_args_message
=
getattr
(
self
,
'missing_args_message'
,
None
),
called_from_command_line
=
getattr
(
self
,
'_called_from_command_line'
,
None
),
)
# Add command-specific arguments first so that they appear in the
# --help output before arguments common to all commands.
...
...
tests/user_commands/management/commands/subparser.py
0 → 100644
Dosyayı görüntüle @
dd68b51e
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
subparsers
=
parser
.
add_subparsers
()
parser_foo
=
subparsers
.
add_parser
(
'foo'
)
parser_foo
.
add_argument
(
'bar'
,
type
=
int
)
def
handle
(
self
,
*
args
,
**
options
):
self
.
stdout
.
write
(
','
.
join
(
options
))
tests/user_commands/tests.py
Dosyayı görüntüle @
dd68b51e
...
...
@@ -206,6 +206,16 @@ class CommandTests(SimpleTestCase):
self
.
assertIn
(
'need_me'
,
out
.
getvalue
())
self
.
assertIn
(
'needme2'
,
out
.
getvalue
())
def
test_subparser
(
self
):
out
=
StringIO
()
management
.
call_command
(
'subparser'
,
'foo'
,
12
,
stdout
=
out
)
self
.
assertIn
(
'bar'
,
out
.
getvalue
())
def
test_subparser_invalid_option
(
self
):
msg
=
"Error: invalid choice: 'test' (choose from 'foo')"
with
self
.
assertRaisesMessage
(
CommandError
,
msg
):
management
.
call_command
(
'subparser'
,
'test'
,
12
)
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