summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2010-01-04 21:43:02 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2010-01-04 21:43:02 (GMT)
commitb9c3ed4f82d3551c9906da55ddb8059ac3b5ce94 (patch)
tree7441a9b687024e4f7f73f640722f80b04a2ce586
parent2bcd17727027b6c923340209f8c6b92e34c69556 (diff)
downloadcpython-b9c3ed4f82d3551c9906da55ddb8059ac3b5ce94.zip
cpython-b9c3ed4f82d3551c9906da55ddb8059ac3b5ce94.tar.gz
cpython-b9c3ed4f82d3551c9906da55ddb8059ac3b5ce94.tar.bz2
#3340: document print/get_usage and print/get_version
-rw-r--r--Doc/library/optparse.rst26
1 files changed, 26 insertions, 0 deletions
diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst
index 1ccf10e..20c9213 100644
--- a/Doc/library/optparse.rst
+++ b/Doc/library/optparse.rst
@@ -603,6 +603,20 @@ For example, if your script is called ``/usr/bin/foo``::
$ /usr/bin/foo --version
foo 1.0
+The following two methods can be used to print and get the ``version`` string:
+
+.. method:: OptionParser.print_version(file=None)
+
+ Print the version message for the current program (``self.version``) to
+ *file* (default stdout). As with :meth:`print_usage`, any occurrence
+ of ``"%prog"`` in ``self.version`` is replaced with the name of the current
+ program. Does nothing if ``self.version`` is empty or undefined.
+
+.. method:: OptionParser.get_version()
+
+ Same as :meth:`print_version` but returns the version string instead of
+ printing it.
+
.. _optparse-how-optparse-handles-errors:
@@ -1389,6 +1403,18 @@ OptionParser supports several other public methods:
constructor keyword argument. Passing ``None`` sets the default usage
string; use :data:`optparse.SUPPRESS_USAGE` to suppress a usage message.
+.. method:: OptionParser.print_usage(file=None)
+
+ Print the usage message for the current program (``self.usage``) to *file*
+ (default stdout). Any occurrence of the string ``"%prog"`` in ``self.usage``
+ is replaced with the name of the current program. Does nothing if
+ ``self.usage`` is empty or not defined.
+
+.. method:: OptionParser.get_usage()
+
+ Same as :meth:`print_usage` but returns the usage string instead of
+ printing it.
+
.. method:: OptionParser.set_defaults(dest=value, ...)
Set default values for several option destinations at once. Using