Command Plugin

Allows you to configure and run custom shell commands.

Example: Starting off simple

In this first example we will create a command that echos a static string into a text file.

ctl:
  plugins:

    - type: command
      name: echo
      config:

        # we want the subprocess to have shell behaviour for
        # for this command (caution advised)

        shell: true
        command:
          - "echo 'this is an example' > example.txt"


  permissions:
    - namespace: ctl
      permission: crud

Run the command

The command will be exposed as an operation to the ctl cli

ctl echo

[2019-10-09 07:55:34,916] [usage] ran command: `echo`

Then verify that it did a thing

cat example.txt

this is an example

Example: Custom arguments

Taking the example from above we can make it a tiny bit more useful, and give some arguments to our command

ctl:
  plugins:

    - type: command
      name: better_echo
      config:

        # we can sepcify custom arguments for the command

        arguments:

          # first positional argument: content
          - name: content
            type: str

          # second positional argument: output file
          - name: output
            type: str
            help: echo to this file
            default: example.txt

        shell: true
        command:
          - "echo '{{ kwargs.content }}' > {{ kwargs.output }}"


  permissions:
    - namespace: ctl
      permission: crud

We can check that our arguments are in place by running the --help function

ctl better_echo --help

usage: ctl better_echo [-h] [--working-dir WORKING_DIR] [content] [output]

positional arguments:
  content
  output                echo to this file

optional arguments:
  -h, --help            show this help message and exit
  --working-dir WORKING_DIR
                        set a working directory before running the commands

Looking good, so now we run our improved echo command like this

ctl better_echo "marginally more useful" better_example.txt

Usage

usage: ctl test_chain [-h] [--end END] [--start START]

optional arguments:
  -h, --help     show this help message and exit
  --end END      stop at this stage
  --start START  start at this stage