-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-14102: argparse: Add generate man page #1169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very nice. It didn't actually run the code, but it should be possible to do something like python3 -c 'import mymodule; mymodule.parser().print_manpage()
from the build system without any fuss.
Doc/library/argparse.rst
Outdated
|
||
.. method:: ArgumentParser.add_manpage_section(heading, description) | ||
|
||
Adding new section to man page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Add a new section to the man page. This only has an effect if print_manpage
is used."
Doc/library/argparse.rst
Outdated
|
||
Description of parameters: | ||
|
||
* heading: title of the section, it will automatically convert to upper case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the title of the section, it will be automatically converted to upper case"
Doc/library/argparse.rst
Outdated
Description of parameters: | ||
|
||
* heading: title of the section, it will automatically convert to upper case | ||
* description: description about this section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called content
. What is the format of this text? Raw TROFF? This should be documented.
Doc/library/argparse.rst
Outdated
* heading: title of the section, it will automatically convert to upper case | ||
* description: description about this section | ||
|
||
Some example usage:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some
Doc/library/argparse.rst
Outdated
|
||
Some example usage:: | ||
|
||
>>> # Adding Copyright section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Add a Copyright section"
Lib/argparse.py
Outdated
# no help; start on same line and add a final newline | ||
if not action.help: | ||
tup = self._current_indent, '', action_header | ||
action_header = '%*s%s' % tup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, why %-formatting here?
action_header = '{:{}}{}'.format('', self._current_indent, action_header)
Lib/argparse.py
Outdated
# short action name; start on the same line and pad two spaces | ||
elif len(action_header) <= action_width: | ||
tup = self._current_indent, '', action_width, action_header | ||
action_header = '%*s%-*s ' % tup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
action_header = '{:{}}{:>{}}'.format('', self._current_indent, action_header, action_width)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is better or not, letting this be a longer line.
This code is from argparse
itself.
Lib/argparse.py
Outdated
action_width = help_position - self._current_indent - 2 | ||
action_header = self._format_action_invocation(action) | ||
|
||
# no help; start on same line and add a final newline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those comments should be moved under the if
, and then the whole if
-ifelse
-else
does not need to be divided by empty lines.
Lib/argparse.py
Outdated
@@ -2345,6 +2491,11 @@ def format_help(self): | |||
# determine help from format above | |||
return formatter.format_help() | |||
|
|||
def format_manpage(self): | |||
formatter = self._get_formatter() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spurious empty line.
Misc/NEWS
Outdated
@@ -313,6 +313,8 @@ Extension Modules | |||
Library | |||
------- | |||
|
|||
- bpo-14102: argparse now can generate Unix man page. Patch by Louie Lu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"UNIX man pages"
Codecov Report
@@ Coverage Diff @@
## master #1169 +/- ##
==========================================
- Coverage 83.44% 83.42% -0.03%
==========================================
Files 1367 1367
Lines 346017 346108 +91
==========================================
+ Hits 288721 288727 +6
- Misses 57296 57381 +85
Continue to review full report at Codecov.
|
OPTIONS | ||
optional arguments | ||
-h, --help | ||
show this help message and exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this the real output? I would expect the command to print out the man page markup, so that it can be saved as a program.1
file and distributed by downstream packagers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the code does produce the markup as I expected!
It’s the example that’s missing something:
$ python myprogram.py --manpage | nroff -man
...
As this pull request has an 'unknown repository' for its branch, I'm going to close it. There is a lot of discussion for this issue on the bug tracker, so any replacement pull request should take all the open concerns into consideration. |
No description provided.