ctl.plugins.command

A plugin that allows you to run one or several shell commands

Classes


CommandPlugin

CommandPlugin(ctl.plugins.ExecutablePlugin)

runs a command

Class Attributes

  • ConfigSchema (ConfigSchema Class): Base plugin config schema

Instanced Attributes

These attributes / properties will be available on instances of the class

during command execution - env (dict): shell environment variables that will be set - stdin: stdin target - stdout: stdout target

Methods

_exec

def _exec(self, command)

execute a single command

this is called automatically during _run_commands

Argument(s)

  • command (str)

Returns

  • int: process return code

_run_commands

def _run_commands(self, command, **kwargs)

execute a list of commands

this is called automatically during execute

Argument(s)

  • command (list): list of shell commands

Returns

  • False if command failed with error

cwd_ctx

def cwd_ctx(self, cwd)

Returns a context manager that allows you to execute commands in a new working directory

Arguments

  • cwd str: path to directory

Returns

CwdContext context


execute

def execute(self, **kwargs)

execute the command(s) specified in the plugin config command list

overrides and calls ExecutablePlugin.execute

Exposed to CLI

namespace: ctl.{plugin_name}


prepare

def prepare(self, **kwargs)

prepares the command environment

cwd, shell env, stdout / stdin are all set up through this

this is called automatically during the ExecutablePlugin.execute call

overrides ExecutablePlugin.prepare


CommandPluginConfig

CommandPluginConfig(confu.schema.core.Schema)

configuration schema for command plugin

Class Attributes

  • arguments (List<ArgparseSchema>): arbirtrary cli arguments
  • command (List<Str>): shell commands to run
  • env (Dict<Str>): environment variables
  • shell (Bool): run subprocess in shell mode
  • working_dir (Directory): set a working directory before running the commands

CwdContext

CwdContext(builtins.object)

A context manager that allows you to temporarily execute commands in a different working directory

Methods

__enter__

def __enter__(self)

Returns

new working directory (str)


__init__

def __init__(self, plugin, cwd)

Arguments

  • plugin (PluginBase): plugin instance
  • cwd (str): set current working directory to this path