{"modulePath":"github.com/algolia/cli","version":"v1.18.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package interactive\n\nPackage interactive builds request bodies by prompting the user for each field of a Go struct via reflection. Input is gathered through the Prompter interface so the traversal can be unit-tested without a terminal.\n\n## Constants\n\n```go\nconst DefaultMaxDepth = 20\n```\nDefaultMaxDepth bounds recursion to defeat self-referential unions. When the guard fires the builder degrades to a raw-JSON prompt.\n\n```go\nconst DefaultParamBagThreshold = 15\n```\nDefaultParamBagThreshold is the optional-field count above which a struct is treated as a parameter bag (the user multi-selects which fields to set).\n\n## Types\n\n```go\ntype Builder struct {\n\tPrompter          Prompter\n\tMaxDepth          int // 0 uses DefaultMaxDepth\n\tParamBagThreshold int // 0 uses DefaultParamBagThreshold\n}\n```\nBuilder prompts for every field of a struct via reflection.\n\n```go\nfunc (b *Builder) Build(v any) error\n```\nBuild reflectively prompts for every field of the struct pointed to by v. v must be a non-nil pointer to a struct. Fields already non-zero on v are preserved (lets the caller pre-populate identifiers).\n\n```go\ntype Prompter interface {\n\t// Input reads a free-text line. validate, when non-nil, is run on the entry;\n\t// the implementation re-prompts until it passes (SurveyPrompter) or surfaces\n\t// its error (ScriptedPrompter). Pass nil for no validation. An empty entry\n\t// means \"skip\" for optional fields and zero for required scalars.\n\tInput(label string, validate func(string) error) (string, error)\n\t// Confirm asks a yes/no question.\n\tConfirm(label string) (bool, error)\n\t// Select asks the user to pick exactly one option and returns the chosen\n\t// label.\n\tSelect(label string, options []string) (string, error)\n\t// MultiSelect asks the user to pick zero or more options and returns the\n\t// chosen 0-based indexes.\n\tMultiSelect(label string, options []string) ([]int, error)\n}\n```\nPrompter is the input surface used by the reflective Builder. Production code uses SurveyPrompter; tests use a scripted fake.\n\n```go\ntype ScriptedPrompter struct {\n\tInputs       map[string]string\n\tConfirms     map[string]bool\n\tSelects      map[string]string\n\tMultiSelects map[string][]int\n}\n```\nScriptedPrompter is a deterministic Prompter for tests. Answers are keyed by a substring of the prompt label rather than by call order, so a test does not break when the target struct (for example a generated SDK type) adds or reorders fields. A prompt whose label matches no key returns a safe default: empty input, a false confirm, the first option, or no multi-selection. Unknown or newly added fields are therefore simply skipped.\n\nMatching rule: a key matches a label when the label equals the key or contains it as a substring. An exact match wins over any substring match; among substring matches the longest (most specific) key wins, so the result is deterministic regardless of map iteration order.\n\n```go\nfunc (p *ScriptedPrompter) Confirm(label string) (bool, error)\n```\n\n```go\nfunc (p *ScriptedPrompter) Input(label string, validate func(string) error) (string, error)\n```\n\n```go\nfunc (p *ScriptedPrompter) MultiSelect(label string, options []string) ([]int, error)\n```\n\n```go\nfunc (p *ScriptedPrompter) Select(label string, options []string) (string, error)\n```\n\n```go\ntype SurveyPrompter struct {\n\t// contains filtered or unexported fields\n}\n```\nSurveyPrompter implements Prompter using survey/v2 via the repo's pkg/prompt wrappers (which are swappable in tests).\n\n```go\nfunc NewSurveyPrompter(io *iostreams.IOStreams) *SurveyPrompter\n```\nNewSurveyPrompter returns a Prompter that reads and writes the given streams.\n\n```go\nfunc (s *SurveyPrompter) Confirm(label string) (bool, error)\n```\n\n```go\nfunc (s *SurveyPrompter) Input(label string, validate func(string) error) (string, error)\n```\n\n```go\nfunc (s *SurveyPrompter) MultiSelect(label string, options []string) ([]int, error)\n```\n\n```go\nfunc (s *SurveyPrompter) Select(label string, options []string) (string, error)\n```\n\n","path":"github.com/algolia/cli/pkg/interactive","name":"interactive","synopsis":"Package interactive builds request bodies by prompting the user for each field of a Go struct via reflection.","isRedistributable":true}
