| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import optparse | 6 import optparse |
| 7 | 7 |
| 8 from telemetry.core import camel_case | 8 from telemetry.core import camel_case |
| 9 | 9 |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 # TODO: Convert everything to argparse. | 58 # TODO: Convert everything to argparse. |
| 59 class OptparseCommand(Command): | 59 class OptparseCommand(Command): |
| 60 usage = '' | 60 usage = '' |
| 61 | 61 |
| 62 @classmethod | 62 @classmethod |
| 63 def CreateParser(cls): | 63 def CreateParser(cls): |
| 64 return optparse.OptionParser('%%prog %s %s' % (cls.Name(), cls.usage), | 64 return optparse.OptionParser('%%prog %s %s' % (cls.Name(), cls.usage), |
| 65 description=cls.Description()) | 65 description=cls.Description()) |
| 66 | 66 |
| 67 @classmethod | |
| 68 def AddCommandLineArgs(cls, parser, environment): | |
| 69 # pylint: disable=arguments-differ | |
| 70 pass | |
| 71 | |
| 72 @classmethod | |
| 73 def ProcessCommandLineArgs(cls, parser, args, environment): | |
| 74 # pylint: disable=arguments-differ | |
| 75 pass | |
| 76 | |
| 77 def Run(self, args): | 67 def Run(self, args): |
| 78 raise NotImplementedError() | 68 raise NotImplementedError() |
| 79 | 69 |
| 80 @classmethod | 70 @classmethod |
| 81 def main(cls, args=None): | 71 def main(cls, args=None): |
| 82 """Main method to run this command as a standalone script.""" | 72 """Main method to run this command as a standalone script.""" |
| 83 parser = cls.CreateParser() | 73 parser = cls.CreateParser() |
| 84 cls.AddCommandLineArgs(parser) | 74 cls.AddCommandLineArgs(parser) |
| 85 options, args = parser.parse_args(args=args) | 75 options, args = parser.parse_args(args=args) |
| 86 options.positional_args = args | 76 options.positional_args = args |
| (...skipping 25 matching lines...) Expand all Loading... |
| 112 command.Name(), help=command.Description()) | 102 command.Name(), help=command.Description()) |
| 113 subparser.set_defaults(command=command) | 103 subparser.set_defaults(command=command) |
| 114 command.AddCommandLineArgs(subparser) | 104 command.AddCommandLineArgs(subparser) |
| 115 | 105 |
| 116 @classmethod | 106 @classmethod |
| 117 def ProcessCommandLineArgs(cls, parser, args): | 107 def ProcessCommandLineArgs(cls, parser, args): |
| 118 args.command.ProcessCommandLineArgs(parser, args) | 108 args.command.ProcessCommandLineArgs(parser, args) |
| 119 | 109 |
| 120 def Run(self, args): | 110 def Run(self, args): |
| 121 return args.command().Run(args) | 111 return args.command().Run(args) |
| OLD | NEW |