bpo-14102: argparse: Add generate man page#1169
bpo-14102: argparse: Add generate man page#1169louisom wants to merge 12 commits intopython:masterfrom louisom:bpo-14102-argparser-manpage
Conversation
keszybz
left a comment
There was a problem hiding this comment.
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.
"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.
"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.
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:: |
Doc/library/argparse.rst
Outdated
|
|
||
| Some example usage:: | ||
|
|
||
| >>> # Adding Copyright section |
| # 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.
Argh, why %-formatting here?
action_header = '{:{}}{}'.format('', self._current_indent, action_header)| # 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.
action_header = '{:{}}{:>{}}'.format('', self._current_indent, action_header, action_width)There was a problem hiding this comment.
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.
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
|
|
||
| def format_manpage(self): | ||
| formatter = self._get_formatter() | ||
|
|
Misc/NEWS
Outdated
| Library | ||
| ------- | ||
|
|
||
| - bpo-14102: argparse now can generate Unix man page. Patch by Louie Lu. |
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.
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.
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.