builder

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEnvPrompt

func NewEnvPrompt(config EnvConfig, store *Store) strumt.Prompter

NewEnvPrompt creates a prompt to populate an environment variable

func NewEnvPrompts

func NewEnvPrompts(configs []EnvConfig, store *Store) []strumt.Prompter

NewEnvPrompts creates several prompts at once to populate environments variables

func NewGroupEnvPromptWithCounter

func NewGroupEnvPromptWithCounter(configs []EnvConfig, store *Store) []strumt.Prompter

NewGroupEnvPromptWithCounter gives the ability to create several group of related environment variable, a common prefix provided as a number from an internal counter tied variable together. For instance in variables environments TEST_*_KEY and TEST_*_VALUE, * is replaced with a number, it becomes TEST_0_KEY and TEST_0_VALUE another call would give TEST_1_VALUE and TEST_1_KEY

func NewSwitchPrompt

func NewSwitchPrompt(ID string, choices []SwitchConfig) strumt.Prompter

NewSwitchPrompt creates a new prompt used to provides several choices, like a menu can do

func ParseEnv

func ParseEnv(validator func(string) error, env string, defaultValue string, store *Store) func(value string) error

ParseEnv provides an env parser callback

Types

type EnvConfig

type EnvConfig struct {
	ID                  string
	NextID              string
	Env                 string
	PromptString        string
	Validator           func(value string) error
	DefaultValue        string
	RunBeforeNextPrompt func(value string, store *Store)
}

EnvConfig is common config for all environments variables prompts builder

type GenericPrompt

type GenericPrompt struct {
	PromptID   string
	PromptStr  string
	OnSuccess  func(string) string
	OnError    func(error) string
	ParseValue func(string) error
}

GenericPrompt defines a generic overridable prompt

func (*GenericPrompt) ID

func (t *GenericPrompt) ID() string

ID return ID of current prompt

func (*GenericPrompt) NextOnError

func (t *GenericPrompt) NextOnError(err error) string

NextOnError returns an error when something wrong occurred

func (*GenericPrompt) NextOnSuccess

func (t *GenericPrompt) NextOnSuccess(value string) string

NextOnSuccess returns the next prompt to reach when succeed

func (*GenericPrompt) Parse

func (t *GenericPrompt) Parse(value string) error

Parse handles prompt value

func (*GenericPrompt) PromptString

func (t *GenericPrompt) PromptString() string

PromptString returns string given by prompt

type Store

type Store map[string]string

Store is a storage for environment variable defined through prompt

type SwitchConfig

type SwitchConfig struct {
	Choice       string
	PromptString string
	NextPromptID string
}

SwitchConfig provides a configuration to switch prompt

Jump to

Keyboard shortcuts

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