|
3 | 3 |
|
4 | 4 | """Command-line support for coverage.py.""" |
5 | 5 |
|
6 | | - |
7 | 6 | import glob |
8 | 7 | import optparse # pylint: disable=deprecated-module |
9 | 8 | import os |
|
25 | 24 | from coverage.execfile import PyRunner |
26 | 25 | from coverage.results import Numbers, should_fail_under |
27 | 26 |
|
| 27 | +# When adding to this file, alphabetization is important. Look for |
| 28 | +# "alphabetize" comments throughout. |
28 | 29 |
|
29 | 30 | class Opts: |
30 | 31 | """A namespace class for individual options we'll build parsers from.""" |
31 | 32 |
|
| 33 | + # Keep these entries alphabetized (roughly) by the option name as it |
| 34 | + # appears on the command line. |
| 35 | + |
32 | 36 | append = optparse.make_option( |
33 | 37 | '-a', '--append', action='store_true', |
34 | 38 | help="Append coverage data to .coverage, otherwise it starts clean each time.", |
@@ -232,6 +236,7 @@ def __init__(self, *args, **kwargs): |
232 | 236 | add_help_option=False, *args, **kwargs |
233 | 237 | ) |
234 | 238 | self.set_defaults( |
| 239 | + # Keep these arguments alphabetized by their names. |
235 | 240 | action=None, |
236 | 241 | append=None, |
237 | 242 | branch=None, |
@@ -337,14 +342,19 @@ def get_prog_name(self): |
337 | 342 | # Include the sub-command for this parser as part of the command. |
338 | 343 | return f"{program_name} {self.cmd}" |
339 | 344 |
|
| 345 | +# In lists of Opts, keep them alphabetized by the option names as they appear |
| 346 | +# on the command line, since these lists determine the order of the options in |
| 347 | +# the help output. |
| 348 | +# |
| 349 | +# In COMMANDS, keep the keys (command names) alphabetized. |
340 | 350 |
|
341 | 351 | GLOBAL_ARGS = [ |
342 | 352 | Opts.debug, |
343 | 353 | Opts.help, |
344 | 354 | Opts.rcfile, |
345 | 355 | ] |
346 | 356 |
|
347 | | -CMDS = { |
| 357 | +COMMANDS = { |
348 | 358 | 'annotate': CmdOptionParser( |
349 | 359 | "annotate", |
350 | 360 | [ |
@@ -595,7 +605,7 @@ def command_line(self, argv): |
595 | 605 | if self.global_option: |
596 | 606 | parser = GlobalOptionParser() |
597 | 607 | else: |
598 | | - parser = CMDS.get(argv[0]) |
| 608 | + parser = COMMANDS.get(argv[0]) |
599 | 609 | if not parser: |
600 | 610 | show_help(f"Unknown command: {argv[0]!r}") |
601 | 611 | return ERR |
@@ -752,7 +762,7 @@ def do_help(self, options, args, parser): |
752 | 762 | if options.action == "help": |
753 | 763 | if args: |
754 | 764 | for a in args: |
755 | | - parser = CMDS.get(a) |
| 765 | + parser = COMMANDS.get(a) |
756 | 766 | if parser: |
757 | 767 | show_help(parser=parser) |
758 | 768 | else: |
|
0 commit comments