prompt



Prompt the user for input with interactive questions

Schema

github.com/hofstadter.io/hof/flow/tasks/prompt

package prompt

import (
  schema "github.com/hofstadter-io/hof/schema/prompt"
)

// Same prompt from creators as a workflow task
Prompt: schema.Prompt & {
  @task(prompt.Prompt)
}

github.com/hofstadter.io/hof/schemas/prompt

package prompt

import (
	"github.com/hofstadter-io/hof/schema/common"
)

Prompt: {
	// the value / schema to be filled in
	// partially filled is supported, questions will be skipped
	Input: {...}

	// the prompt questions
	Questions: [...Question]

	// the resulting value after prompt
	Output: {...}
}

Question: {
	Name:   string
	Type:   "input" | "multiline" | "password" | "confirm" | "select" | "multiselect" | "subgroup"
	Prompt: string
	// for (multi)select
	Options?: [...string]
	Default?:    _
	Required:    bool | *false
	Validation?: _

	Questions?: [...Question]
}

NamePrompt: {
	Name:       "name"
	Type:       "input"
	Prompt:     "What is your CLI named"
	Required:   true
	Validation: common.NameLabel
}

RepoPrompt: {
	Name:       "repo"
	Type:       "git"
	Prompt:     "Git repository"
	Validation: common.NameLabel
}

Example

prompt example

package prompt

import "encoding/json"

test: {
	@flow()

	prompt: {
		@task(prompt.Prompt)

		Input: {
			name:     string
			repo:     string
			releases: bool | *false
		}

		Questions: [{
			Name:     "name"
			Type:     "input"
			Prompt:   "What is your project named"
			Required: true
		}, {
			Name:    "repo"
			Type:    "input"
			Prompt:  "Git repository"
			Default: "github.com/user/repo"
		}, {
			Name:    "releases"
			Type:    "confirm"
			Prompt:  "Enable release tooling"
			Default: true
		}]

		Output: _
	}

	output: {
		@task(os.Stdout)
		text: json.Indent(json.Marshal(prompt.Output), "", "  ")
	}

}