Skip to content

Command API

Federico Conticello edited this page Mar 24, 2026 · 1 revision

Command API

Plugins can execute external commands (linters, formatters, build tools) with user-approved permissions.

api:run_command(cmd, ...args)

Runs an external command and returns the result.

local result = api:run_command("ruff", "check", "--output-format=json", file_path)
if result.success then
    local output = result.stdout
    -- parse output
else
    api:log("Command failed: " .. result.stderr)
end

Return Value

A table with:

Field Type Description
stdout string Captured standard output
stderr string Captured standard error
success boolean true if exit code was 0

Behavior

  • Working directory is set to the project root (if detected)
  • Timeout: 30 seconds — the process is killed after this
  • Arguments are passed as separate values, not as a shell string

Security

The command must be listed in [permissions] execute in your plugin.toml:

[permissions]
execute = ["ruff", "pyright"]

On first run, FerrisPad prompts the user to approve the command. The user can:

  • Allow — the command runs and is remembered for this plugin
  • Deny — the command is blocked

Arguments are validated to block shell injection. These characters are forbidden:

; & | ` $ ( ) { } < > \n \r \ * ? [ ]

api:command_exists(cmd)

Checks if a command is available on the system PATH. Returns true or false.

if not api:command_exists("eslint") then
    return {
        status_message = {
            level = "warning",
            text = "ESLint not found. Install it with: npm install -g eslint"
        }
    }
end

This does not require any permissions — it only checks existence, not execution.

Clone this wiki locally