提交 ff1238d5 编写于 作者: C Cleber Rosa

New Plugin Architecture: introduce CLICmd

The CLICmd, is a base class for plugins that want to add commands
to the Avocado command line application. These commands should be
given by a user right after the command line application itself, as
it's common practice in most CLI tools.

This class has minimal functionality (some in the configure method),
and its main goal is to define the interface that plugin developers
should follow.

The only mandatory steps for "CLICmd" plugins are a name, and the
`run` method. `configure` will, by default register the command
with Avocado command line parser.

By doing just that, the new command is visible on the Avocado command
line application. So, if a plugin named "foo" would introduce a
command with the same name (ideally, for consistency) it would be
called with:

 $ avocado foo

And it's help message would be visible with:

 $ avocado foo --help

Other command line options to a given introduced command can be added
by writing a custom `configure` method.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 5cbe1550
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2015
# Author: Cleber Rosa <cleber@redhat.com>
import abc
class Plugin(object):
"""
Base for all plugins
"""
class CLICmd(Plugin):
"""
Base plugin interface for adding new commands to the command line app
Plugins that want to add extensions to the run command should use the
'avocado.plugins.cli.cmd' namespace.
"""
__metaclass__ = abc.ABCMeta
name = None
description = None
def __init__(self):
super(CLICmd, self).__init__()
def configure(self, parser):
"""
Lets the extension add command line options and do early configuration
By default it will register its `name` as the command name and give
its `description` as the help message.
"""
help_msg = self.description
if help_msg is None:
help_msg = 'Runs the %s command' % self.name
parser = parser.subcommands.add_parser(self.name,
help=help_msg)
return parser
@abc.abstractmethod
def run(self, args):
"""
Entry point for actually running the command
"""
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册