summaryrefslogtreecommitdiff
path: root/coverage/cmdline.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/cmdline.py')
-rw-r--r--coverage/cmdline.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 46a87ca6..221c18d6 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -228,7 +228,6 @@ class CmdOptionParser(CoverageOptionParser):
if usage:
usage = "%prog " + usage
super(CmdOptionParser, self).__init__(
- prog="coverage %s" % action,
usage=usage,
description=description,
)
@@ -242,6 +241,14 @@ class CmdOptionParser(CoverageOptionParser):
# results, and they will compare equal to objects.
return (other == "<CmdOptionParser:%s>" % self.cmd)
+ def get_prog_name(self):
+ """Override of an undocumented function in optparse.OptionParser."""
+ program_name = super(CmdOptionParser, self).get_prog_name()
+
+ # Include the sub-command for this parser as part of the command.
+ return "%(command)s %(subcommand)s" % {'command': program_name, 'subcommand': self.cmd}
+
+
GLOBAL_ARGS = [
Opts.debug,
Opts.help,
@@ -390,6 +397,17 @@ class CoverageScript(object):
self.coverage = None
+ self.program_name = os.path.basename(sys.argv[0])
+ if env.WINDOWS:
+ # entry_points={'console_scripts':...} on Windows makes files
+ # called coverage.exe, coverage3.exe, and coverage-3.5.exe. These
+ # invoke coverage-script.py, coverage3-script.py, and
+ # coverage-3.5-script.py. argv[0] is the .py file, but we want to
+ # get back to the original form.
+ auto_suffix = "-script.py"
+ if self.program_name.endswith(auto_suffix):
+ self.program_name = self.program_name[:-len(auto_suffix)]
+
def command_line(self, argv):
"""The bulk of the command line interface to coverage.py.
@@ -523,13 +541,15 @@ class CoverageScript(object):
assert error or topic or parser
if error:
print(error)
- print("Use 'coverage help' for help.")
+ print("Use '%s help' for help." % (self.program_name,))
elif parser:
print(parser.format_help().strip())
else:
+ help_params = dict(self.covpkg.__dict__)
+ help_params['program_name'] = self.program_name
help_msg = textwrap.dedent(HELP_TOPICS.get(topic, '')).strip()
if help_msg:
- print(help_msg % self.covpkg.__dict__)
+ print(help_msg % help_params)
else:
print("Don't know topic %r" % topic)
@@ -682,7 +702,7 @@ HELP_TOPICS = {
Coverage.py, version %(__version__)s
Measure, collect, and report on code coverage in Python programs.
- usage: coverage <command> [options] [args]
+ usage: %(program_name)s <command> [options] [args]
Commands:
annotate Annotate source files with execution information.
@@ -694,12 +714,12 @@ HELP_TOPICS = {
run Run a Python program and measure code execution.
xml Create an XML report of coverage results.
- Use "coverage help <command>" for detailed help on any command.
+ Use "%(program_name)s help <command>" for detailed help on any command.
For full documentation, see %(__url__)s
""",
'minimum_help': """\
- Code coverage for Python. Use 'coverage help' for help.
+ Code coverage for Python. Use '%(program_name)s help' for help.
""",
'version': """\