1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
from telemetry.internal.util import command_line
class ArgParseCommand(command_line.Command):
usage = ''
@classmethod
def CreateParser(cls):
return argparse.ArgumentParser('%%prog %s %s' % (cls.Name(), cls.usage),
description=cls.Description())
@classmethod
def AddCommandLineArgs(cls, parser, environment):
# pylint: disable=arguments-differ
pass
@classmethod
def ProcessCommandLineArgs(cls, parser, options, extra_args, environment):
# pylint: disable=arguments-differ
pass
def Run(self, options, extra_args=None):
# pylint: disable=arguments-differ
raise NotImplementedError()
@classmethod
def main(cls, args=None):
"""Main method to run this command as a standalone script."""
parser = cls.CreateParser()
cls.AddCommandLineArgs(parser, None)
options, extra_args = parser.parse_known_args(args=args)
cls.ProcessCommandLineArgs(parser, options, extra_args, None)
return min(cls().Run(options, extra_args), 255)
|