Browse files

Started work on plugin support

Plugins are python modules included with the CLI that are not generated
from the OpenAPI spec.  At this time, plugins must be accepted in the
mainline CLI repo to be installed.  See for more information
on plugin support.
  • Loading branch information...
Dorthu committed Nov 10, 2018
1 parent 203f4f3 commit 988fb195ab8495522b9752f9495ab6bd3984852a
Showing with 65 additions and 1 deletion.
  1. +6 −0 linodecli/
  2. +31 −0 linodecli/plugins/
  3. +16 −0 linodecli/plugins/
  4. +8 −0 linodecli/plugins/
  5. +4 −1
@@ -14,6 +14,7 @@
from .response import ModelAttr, ResponseModel
from .operation import CLIArg, CLIOperation, URLParam
from .output import OutputMode
from linodecli import plugins
# this might not be installed at the time of building
@@ -160,6 +161,11 @@ def main():
if parsed.command == 'bake-bash':
# check for plugin invocation
if parsed.command not in cli.ops and parsed.command in plugins.available:
plugins.invoke(parsed.command, argv[2:], None)
# handle a help for a command - either --help or no action triggers this
if parsed.command is not None and parsed.action is None:
if parsed.command in cli.ops:
@@ -0,0 +1,31 @@
# plugin support
The Linode CLI supports embedded plugins, features that are hard-coded (instead
of generated as the rest of the CLI is) but are accessible directly through the
CLI as other features are. All plugins are found in this directory.
## Creating a Plugin
To create a plugin, simply drop a new python file into this directory. The
plugin must meet the following conditions:
* Its name must be unique, both with the other plugins and with all commands
offered through the generated CLI
* Its name must not contain special characters, and should be easily enter able
on the command line
* It must support a `--help` command as all other CLI commands do.
## The Plugin Interface
All plugins are individual python files that reside in this directory. Plugins
must have one function, `call`, that matches the following signature:
def call(args, context):
This is the function used to invoke the plugin. It will receive the remaineder
of sys.argv after the plugin's name, and a context of user defaults and config
@@ -0,0 +1,16 @@
from importlib import import_module
from os import listdir
from os.path import dirname
_available_files = listdir(dirname(__file__))
available = [f[:-3] for f in _available_files if f.endswith('.py') and f != '']
def invoke(name, args, context):
Given the plugin name, executes a plugin
if name not in available:
raise ValueError('No plugin named {}'.format(name))
plugin = import_module('linodecli.plugins.'+name), context)
@@ -0,0 +1,8 @@
def call(args, context):
This method is invoked when this plugin is invoked on the command line.
:param args: sys.argv, trimmed to represent only arguments to this command
:type args: list
@@ -42,7 +42,10 @@ def get_version():
license="BSD 3-Clause License",

0 comments on commit 988fb19

Please sign in to comment.