mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-30 12:44:14 +02:00
feat(cli): add plugin install and complete prompt/render host events
This commit is contained in:
10
plugins/template-function-prompt-form-cli-test/package.json
Normal file
10
plugins/template-function-prompt-form-cli-test/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@gschier/prompt-form-cli-test",
|
||||
"displayName": "Prompt Form CLI Test",
|
||||
"description": "Tiny plugin to test prompt.form in the CLI host",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"build": "yaak plugin build"
|
||||
}
|
||||
}
|
||||
59
plugins/template-function-prompt-form-cli-test/src/index.ts
Normal file
59
plugins/template-function-prompt-form-cli-test/src/index.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
export const plugin = {
|
||||
templateFunctions: [
|
||||
{
|
||||
name: 'prompt.form.demo',
|
||||
description: 'Prompt for a few values using prompt.form and return a JSON string',
|
||||
args: [],
|
||||
async onRender(ctx, args) {
|
||||
if (args.purpose !== 'send') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const values = await ctx.prompt.form({
|
||||
id: 'prompt-form-demo',
|
||||
title: 'CLI Prompt Form Demo',
|
||||
description: 'Fill out the fields to test prompt.form in the CLI.',
|
||||
inputs: [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'username',
|
||||
label: 'Username',
|
||||
defaultValue: 'alice'
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'password',
|
||||
label: 'Password',
|
||||
password: true,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
type: 'select',
|
||||
name: 'region',
|
||||
label: 'Region',
|
||||
defaultValue: 'us',
|
||||
options: [
|
||||
{ label: 'US', value: 'us' },
|
||||
{ label: 'EU', value: 'eu' },
|
||||
{ label: 'APAC', value: 'apac' }
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'remember',
|
||||
label: 'Remember',
|
||||
defaultValue: 'true',
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if (values == null) {
|
||||
throw new Error('Prompt form cancelled');
|
||||
}
|
||||
|
||||
return JSON.stringify(values);
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user