| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Parse a command line, retrieving a command and its arguments. | 6 """Parse a command line, retrieving a command and its arguments. |
| 7 | 7 |
| 8 Supports the concept of command line commands, each with its own set | 8 Supports the concept of command line commands, each with its own set |
| 9 of arguments. Supports dependent arguments and mutually exclusive arguments. | 9 of arguments. Supports dependent arguments and mutually exclusive arguments. |
| 10 Basically, a better optparse. I took heed of epg's WHINE() in gvn.cmdline | 10 Basically, a better optparse. I took heed of epg's WHINE() in gvn.cmdline |
| 11 and dumped optparse in favor of something better. | 11 and dumped optparse in favor of something better. |
| 12 """ | 12 """ |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 653 |
| 654 out.write(textwrap.fill(help_cmd.helptext, width)) | 654 out.write(textwrap.fill(help_cmd.helptext, width)) |
| 655 out.write("\n\n") | 655 out.write("\n\n") |
| 656 out.write(help_cmd.GetUsageString(width=width)) | 656 out.write(help_cmd.GetUsageString(width=width)) |
| 657 out.write("\n\n") | 657 out.write("\n\n") |
| 658 out.write(help_cmd.GetHelpString(width=width)) | 658 out.write(help_cmd.GetHelpString(width=width)) |
| 659 out.write("\n") | 659 out.write("\n") |
| 660 | 660 |
| 661 command.cmdline.Exit() | 661 command.cmdline.Exit() |
| 662 | 662 |
| 663 if __name__ == "__main__": | 663 |
| 664 def main(): |
| 664 # If we're invoked rather than imported, run some tests | 665 # If we're invoked rather than imported, run some tests |
| 665 cmdline = CommandLine() | 666 cmdline = CommandLine() |
| 666 | 667 |
| 667 # Since we're testing, override Exit() | 668 # Since we're testing, override Exit() |
| 668 def TestExit(): | 669 def TestExit(): |
| 669 pass | 670 pass |
| 670 cmdline.Exit = TestExit | 671 cmdline.Exit = TestExit |
| 671 | 672 |
| 672 # Actually, while we're at it, let's override error output too | 673 # Actually, while we're at it, let's override error output too |
| 673 cmdline.err = open(os.path.devnull, "w") | 674 cmdline.err = open(os.path.devnull, "w") |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 if not len(cmdline.command.parse_errors) == expected_failures: | 791 if not len(cmdline.command.parse_errors) == expected_failures: |
| 791 print "FAILED:\n issued: '%s'\n expected: %d\n received: %d\n\n" % ( | 792 print "FAILED:\n issued: '%s'\n expected: %d\n received: %d\n\n" % ( |
| 792 test, expected_failures, len(cmdline.command.parse_errors)) | 793 test, expected_failures, len(cmdline.command.parse_errors)) |
| 793 badtests += 1 | 794 badtests += 1 |
| 794 | 795 |
| 795 print "%d failed out of %d tests" % (badtests, len(test_lines)) | 796 print "%d failed out of %d tests" % (badtests, len(test_lines)) |
| 796 | 797 |
| 797 cmdline.ParseCommandLine(["help", "test"]) | 798 cmdline.ParseCommandLine(["help", "test"]) |
| 798 | 799 |
| 799 | 800 |
| 801 if __name__ == "__main__": |
| 802 sys.exit(main()) |
| OLD | NEW |