CLI Trigger
Wick’s CLI Trigger executes whenever an application is executed on the command line (which is almost always). It delegates CLI args and STDIO to an operation which can optionally depend on arbitrary other components to provide dynamic CLI behavior.
Example
Example showing how to wire together a WebAssembly component with a SQL component into a CLI Trigger.
This app configuration starts off with the common Application kind
and a name field.
kind: wick/app@v1
name: db_cli
The CLI trigger is configured with an
operation
that accepts args: string[]
and interactive: { stdin: bool, stdout: bool, stderr: bool }
as input.
This example uses two components, one that provides the CLI interface:
import:
- component:
kind: wick/component/manifest@v1
provide:
db: MYDB
ref: ../../crates/integration/test-cli-with-db/component.yaml
name: CLI
And another that the first component requires, called MYDB. This is a SQL component that provides an interface whose implementation is backed by a SQL query vs compiled code. It’s implementation isn’t important for this example, but you can see it in the full configuration included at the end of this page.
The trigger configuration delegates operation to the main
operation on our CLI
component:
triggers:
- kind: wick/trigger/cli@v1
operation: CLI::main
Our CLI trigger will execute when we run wick run
on the command line.
The full configuration is located at examples/cli/wasm-calling-postgres.wick. Run this application locally by cloning the wick repository and using wick run
(or cargo run -p wick-cli -- run
to run from source)
git clone https://github.com/candlecorp/wick && cd wick
wick run examples/cli/wasm-calling-postgres.wick
Complete Example
Note: Examples may require environment variables and execution from within the wick project’s root to access any local files.
The full example configuration is included below,
name: db_cli
kind: wick/app@v1
metadata:
description: Example showing how to wire together a WebAssembly component with a SQL component into a CLI Trigger.
version: 0.0.1
authors:
- 'Wick Maintainers'
vendors:
- 'Candle Corporation'
licenses:
- Apache-2.0
resources:
- name: DBADDR
resource:
kind: wick/resource/url@v1
url: postgres://postgres:{{ ctx.env.TEST_PASSWORD }}@{{ ctx.env.TEST_HOST }}:{{ ctx.env.POSTGRES_PORT }}/wick_test
import:
- name: MYDB
component:
kind: wick/component/sql@v1
resource: DBADDR
tls: false
operations:
- name: get_user
inputs:
- name: id
type: i32
query: SELECT name FROM users WHERE id = $1
arguments:
- id
- name: CLI
component:
kind: wick/component/manifest@v1
ref: ../../crates/integration/test-cli-with-db/component.yaml
provide:
db: MYDB
triggers:
- kind: wick/trigger/cli@v1
operation: CLI::main