diff options
author | Fred Drake <fdrake@acm.org> | 2004-04-01 07:40:35 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2004-04-01 07:40:35 (GMT) |
commit | 456d3258d64f4c60a7787dd59f5c68bafb81584c (patch) | |
tree | 1fb12da152101e04ddb1504c3845d3744783c096 /Lib/optparse.py | |
parent | 8effa01931b1917ddad7462ba4d1d4223357fe3a (diff) | |
download | cpython-456d3258d64f4c60a7787dd59f5c68bafb81584c.zip cpython-456d3258d64f4c60a7787dd59f5c68bafb81584c.tar.gz cpython-456d3258d64f4c60a7787dd59f5c68bafb81584c.tar.bz2 |
Fix support for the "prog" keyword to the OptionParser constructor, as well
as directly setting the .prog attribute (which should be supported based on
the class docstring).
Closes SF bug #850964.
Diffstat (limited to 'Lib/optparse.py')
-rw-r--r-- | Lib/optparse.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/optparse.py b/Lib/optparse.py index bacef0f..d3593d3 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -1025,6 +1025,11 @@ class OptionParser (OptionContainer): self.largs = None self.values = None + def _get_prog_name(self): + if self.prog: + return self.prog + else: + return get_prog_name() # -- Simple modifier methods --------------------------------------- @@ -1288,12 +1293,12 @@ class OptionParser (OptionContainer): should either exit or raise an exception. """ self.print_usage(sys.stderr) - sys.exit("%s: error: %s" % (get_prog_name(), msg)) + sys.exit("%s: error: %s" % (self._get_prog_name(), msg)) def get_usage (self): if self.usage: return self.formatter.format_usage( - self.usage.replace("%prog", get_prog_name())) + self.usage.replace("%prog", self._get_prog_name())) else: return "" @@ -1311,7 +1316,7 @@ class OptionParser (OptionContainer): def get_version (self): if self.version: - return self.version.replace("%prog", get_prog_name()) + return self.version.replace("%prog", self._get_prog_name()) else: return "" |