This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: argparse with required field , not having new line separator in -help dispaly
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, mohankumar, paul.j3
Priority: normal Keywords:

Created on 2016-03-07 12:18 by mohankumar, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg261297 - (view) Author: Mohankumar (mohankumar) Date: 2016-03-07 12:18
We are using Python argsparse library here to display below --help message .
In --help option , new line option not handled correctly , Especially in "mandatory parameters" (required=True) better to place a new line before for better readability , Since it not having any separators like list brackets in "Non Mandatory parameters".

For example In below help , there must be a new line before "--protocol" and " --action" for better readability

Neutron firewall-rule-create [-h]
                                    [-f {html,json,json,shell,table,value,yaml,yaml}]
                                    [-c COLUMN] [--max-width <integer>]
                                    [--noindent] [--prefix PREFIX]
                                    [--request-format {json,xml}]
                                    [--tenant-id TENANT_ID] [--name NAME]
                                    [--description DESCRIPTION] [--shared]
                                    [--source-ip-address SOURCE_IP_ADDRESS]
                                    [--destination-ip-address DESTINATION_IP_ADDRESS]
                                    [--source-port SOURCE_PORT]
                                    [--destination-port DESTINATION_PORT]
                                    [--enabled {True,False}] --protocol
                                    {tcp,udp,icmp,any} --action
msg261536 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2016-03-11 00:27
The usage line formatter needs a major rewrite.  

Currently it formats usage for all the arguments as one line (two actually, optionals and positionals are handled separately), and then breaks it into 'wrappable parts'.  It then compiles the lines from these parts

                # break usage into wrappable parts
                part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'

So it's keeping things enclosed in brackets together, but allowing the 'required' arguments to be split.

Certain characters like [] in the metavars also break this usage.  

has a patch with a usage rewrite hopefully will take care of this problem.  It collects the formatted arguments in a list rather than a concatenated string, so there's no need for this buggy splitter.
msg394607 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-27 21:22
issue11874 has been fixed and its PR has a unit test that seems similar to the case reported here (test_help_with_metavar). If you are still seeing this issue on 3.9 or higher, please create a new issue and include a code snippet that reproduces the problem.
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70690
2021-05-27 21:22:41iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg394607

resolution: out of date
stage: resolved
2016-03-11 00:27:16paul.j3setnosy: + paul.j3
messages: + msg261536
2016-03-07 12:18:16mohankumarcreate