mirror of
https://github.com/facebook/proxygen.git
synced 2025-08-10 05:22:59 +03:00
Summary: This applies the formatting changes from black v21.4b2 to all covered projects in fbsource. Most changes are to single line docstrings, as black will now remove leading and trailing whitespace to match PEP8. Any other formatting changes are likely due to files that landed without formatting, or files that previously triggered errors in black. Any changes to code should be AST identical. Any test failures are likely due to bad tests, or testing against the output of pyfmt. Reviewed By: thatch Differential Revision: D28204910 fbshipit-source-id: 804725bcd14f763e90c5ddff1d0418117c15809a
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
|
|
class SubCmd(object):
|
|
NAME = None
|
|
HELP = None
|
|
|
|
def run(self, args):
|
|
"""perform the command"""
|
|
return 0
|
|
|
|
def setup_parser(self, parser):
|
|
# Subclasses should override setup_parser() if they have any
|
|
# command line options or arguments.
|
|
pass
|
|
|
|
|
|
CmdTable = []
|
|
|
|
|
|
def add_subcommands(parser, common_args, cmd_table=CmdTable):
|
|
"""Register parsers for the defined commands with the provided parser"""
|
|
for cls in cmd_table:
|
|
command = cls()
|
|
command_parser = parser.add_parser(
|
|
command.NAME, help=command.HELP, parents=[common_args]
|
|
)
|
|
command.setup_parser(command_parser)
|
|
command_parser.set_defaults(func=command.run)
|
|
|
|
|
|
def cmd(name, help=None, cmd_table=CmdTable):
|
|
"""
|
|
@cmd() is a decorator that can be used to help define Subcmd instances
|
|
|
|
Example usage:
|
|
|
|
@subcmd('list', 'Show the result list')
|
|
class ListCmd(Subcmd):
|
|
def run(self, args):
|
|
# Perform the command actions here...
|
|
pass
|
|
"""
|
|
|
|
def wrapper(cls):
|
|
class SubclassedCmd(cls):
|
|
NAME = name
|
|
HELP = help
|
|
|
|
cmd_table.append(SubclassedCmd)
|
|
return SubclassedCmd
|
|
|
|
return wrapper
|