survey

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

stuttgart-things/survey

library module for creating dynamic cli surveys based on huh

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFunctions = make(map[string]func(params map[string]interface{}) string)

DefaultFunctions holds the registered functions

Functions

func BuildSurvey

func BuildSurvey(questions []*Question) (*huh.Form, map[string]interface{}, error)

BUILD THE SURVEY FUNCTION WITH THE NEW RANDOM SETUP

func ConvertToType added in v0.5.0

func ConvertToType(value string, typ string) interface{}

func GetRandomAnswers added in v0.5.0

func GetRandomAnswers(questions []*Question) map[string]interface{}

func ReadYAMLFile added in v0.2.0

func ReadYAMLFile(filePath string) (string, error)

func RegisterFunction added in v0.4.0

func RegisterFunction(name string, fn func(params map[string]interface{}) string)

RegisterFunction adds a function to the registry

func RunSurvey

func RunSurvey(profilePath, surveyKey string) (surveyValues map[string]interface{})

func RunSurveyWithRandomSelects added in v0.4.0

func RunSurveyWithRandomSelects(profilePath, surveyKey string, runSurvey bool) map[string]interface{}

RunSurveyWithRandomSelects runs the survey but generates random answers for select questions if runSurvey is false

Types

type ListModel added in v0.4.1

type ListModel struct {
	FinalOutput string
	// contains filtered or unexported fields
}

func InitListModel added in v0.4.1

func InitListModel(defaultVars []string) ListModel

func (ListModel) Init added in v0.4.1

func (m ListModel) Init() tea.Cmd

func (ListModel) Update added in v0.4.1

func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (ListModel) View added in v0.4.1

func (m ListModel) View() string

type Question

type Question struct {
	Prompt          string                 `yaml:"prompt"`
	Name            string                 `yaml:"name"`
	Default         string                 `yaml:"default,omitempty"`
	DefaultFunction string                 `yaml:"default_function,omitempty"`
	DefaultParams   map[string]interface{} `yaml:"default_params,omitempty"`
	Options         []string               `yaml:"options"`
	Kind            string                 `yaml:"kind,omitempty"` // "function" instead of "text"
	MinLength       int                    `yaml:"minLength,omitempty"`
	MaxLength       int                    `yaml:"maxLength,omitempty"`
	Type            string                 `yaml:"type,omitempty"` // Updated field to match the YAML
}

QUESTION STRUCT TO HOLD THE QUESTION DATA FROM YAML

func LoadQuestionFile

func LoadQuestionFile(filename, yamlKey string) ([]*Question, error)

type Save added in v0.2.0

type Save struct {
	// contains filtered or unexported fields
}

SAVE MODEL HOLDS THE STATE FOR THE SAVE FUNCTIONALITY.

func InitialSaveModel added in v0.2.0

func InitialSaveModel(content string) Save

InitialSaveModel initializes the Save model with a file picker and text input for the filename.

func (Save) Init added in v0.2.0

func (m Save) Init() tea.Cmd

func (Save) Update added in v0.2.0

func (m Save) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Save) View added in v0.2.0

func (m Save) View() string

type Text added in v0.2.0

type Text struct {
	Textarea   textarea.Model
	ErrMsg     string
	Quitting   bool
	WindowSize tea.WindowSizeMsg // Track window size for responsive layout
}

MODEL HOLDS THE STATE FOR THE TERMINAL UI.

func InitialModel added in v0.2.0

func InitialModel(content string) Text

func (Text) Init added in v0.2.0

func (m Text) Init() tea.Cmd

func (Text) Update added in v0.2.0

func (m Text) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Text) View added in v0.2.0

func (m Text) View() string

Directories

Path Synopsis
example
list command
questions command
save command
text command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL