Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external plugin #760

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open

Add external plugin #760

wants to merge 3 commits into from

Conversation

fujiwara
Copy link
Contributor

@fujiwara fujiwara commented Oct 25, 2024

external plugin runs any external commands as template functions.

Execute external commands

The external plugin introduces functions to execute any external commands.

For example, jq -n "{ Now: now | todateiso8601" } returns the current date in ISO8601 format as a JSON object.

$ jq -n "{ Now: now | todateiso8601 }"
{
  "Now": "2024-10-25T16:13:22Z"
}

You can use this command as a template function in the definition files.

First, define the plugin in the configuration file.

ecspresso.yml

plugins:
  - name: external
    config:
      name: jq
      command: ["jq", "-n"]
      num_args: 1
      timeout: 5

The config section defines the following parameters:

  • name: template function name
  • command: external command and arguments (array)
    • The command must output a JSON string or any strings to stdout.
  • num_args: number of arguments (optional, default 0)
  • parser: parser type "json" or "string" (optional, default "json")
  • timeout: command execution timeout seconds (optional, default never timeout)

And use the template function in the definition files as follows.

local jq = std.native('jq');
{
  today: jq('{ Now: now | todateiso8601 }').Now,
}
{
  "today": "{{ (jq `{Now: now | todateiso8601}`).Now }}"
}

external plugin runs any external commands as template functions.
@fujiwara fujiwara mentioned this pull request Oct 31, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant