Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8a6a198a
Commit
8a6a198a
authored
Mar 27, 2011
by
Steven Bethard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #9026: Fix order of argparse sub-commands in help messages.
parent
a6e0b4f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
4 deletions
+84
-4
Lib/argparse.py
Lib/argparse.py
+2
-1
Lib/test/test_argparse.py
Lib/test/test_argparse.py
+80
-3
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/argparse.py
View file @
8a6a198a
...
...
@@ -82,6 +82,7 @@ __all__ = [
]
import
collections
as
_collections
import
copy
as
_copy
import
os
as
_os
import
re
as
_re
...
...
@@ -1041,7 +1042,7 @@ class _SubParsersAction(Action):
self
.
_prog_prefix
=
prog
self
.
_parser_class
=
parser_class
self
.
_name_parser_map
=
{}
self
.
_name_parser_map
=
_collections
.
OrderedDict
()
self
.
_choices_actions
=
[]
super
(
_SubParsersAction
,
self
).
__init__
(
...
...
Lib/test/test_argparse.py
View file @
8a6a198a
...
...
@@ -2837,16 +2837,22 @@ class TestHelpFormattingMetaclass(type):
parser
=
argparse
.
ArgumentParser
(
*
tester
.
parser_signature
.
args
,
**
tester
.
parser_signature
.
kwargs
)
for
argument_sig
in
tester
.
argument_signatures
:
for
argument_sig
in
getattr
(
tester
,
'argument_signatures'
,
[])
:
parser
.
add_argument
(
*
argument_sig
.
args
,
**
argument_sig
.
kwargs
)
group_sig
natures
=
tester
.
argument_group_signatures
for
group_sig
,
argument_sigs
in
group_sig
nature
s
:
group_sig
s
=
getattr
(
tester
,
'argument_group_signatures'
,
[])
for
group_sig
,
argument_sigs
in
group_sigs
:
group
=
parser
.
add_argument_group
(
*
group_sig
.
args
,
**
group_sig
.
kwargs
)
for
argument_sig
in
argument_sigs
:
group
.
add_argument
(
*
argument_sig
.
args
,
**
argument_sig
.
kwargs
)
subparsers_sigs
=
getattr
(
tester
,
'subparsers_signatures'
,
[])
if
subparsers_sigs
:
subparsers
=
parser
.
add_subparsers
()
for
subparser_sig
in
subparsers_sigs
:
subparsers
.
add_parser
(
*
subparser_sig
.
args
,
**
subparser_sig
.
kwargs
)
return
parser
def
_test
(
self
,
tester
,
parser_text
):
...
...
@@ -3940,6 +3946,77 @@ class TestHelpVersionAction(HelpTestCase):
'''
version
=
''
class
TestHelpSubparsersOrdering
(
HelpTestCase
):
"""Test ordering of subcommands in help matches the code"""
parser_signature
=
Sig
(
prog
=
'PROG'
,
description
=
'display some subcommands'
,
version
=
'0.1'
)
subparsers_signatures
=
[
Sig
(
name
=
name
)
for
name
in
(
'a'
,
'b'
,
'c'
,
'd'
,
'e'
)]
usage
=
'''
\
usage: PROG [-h] [-v] {a,b,c,d,e} ...
'''
help
=
usage
+
'''
\
display some subcommands
positional arguments:
{a,b,c,d,e}
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
'''
version
=
'''
\
0.1
'''
class
TestHelpSubparsersWithHelpOrdering
(
HelpTestCase
):
"""Test ordering of subcommands in help matches the code"""
parser_signature
=
Sig
(
prog
=
'PROG'
,
description
=
'display some subcommands'
,
version
=
'0.1'
)
subcommand_data
=
((
'a'
,
'a subcommand help'
),
(
'b'
,
'b subcommand help'
),
(
'c'
,
'c subcommand help'
),
(
'd'
,
'd subcommand help'
),
(
'e'
,
'e subcommand help'
),
)
subparsers_signatures
=
[
Sig
(
name
=
name
,
help
=
help
)
for
name
,
help
in
subcommand_data
]
usage
=
'''
\
usage: PROG [-h] [-v] {a,b,c,d,e} ...
'''
help
=
usage
+
'''
\
display some subcommands
positional arguments:
{a,b,c,d,e}
a a subcommand help
b b subcommand help
c c subcommand help
d d subcommand help
e e subcommand help
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
'''
version
=
'''
\
0.1
'''
# =====================================
# Optional/Positional constructor tests
# =====================================
...
...
Misc/NEWS
View file @
8a6a198a
...
...
@@ -167,6 +167,8 @@ Library
- Issue #9343: Document that argparse parent parsers must be configured before
their children.
- Issue #9026: Fix order of argparse sub-commands in help messages.
Build
-----
...
...
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