Documentation
¶
Index ¶
- Variables
- func Confirm(u UI, title, description string, def bool) (bool, error)
- func RunDiffViewer(ctx context.Context, s DiffSession) (*gitopsdiff.Report, error)
- func RunFullscreen(ctx context.Context, title string, out io.Writer, logPath string, ...) error
- func Select(u UI, title, description string, options []Option, value *string) error
- type Choice
- type Choices
- type Confirmation
- type DiffChoices
- type DiffSelection
- type DiffSession
- type Field
- type Form
- type Fullscreen
- func (f *Fullscreen) Ask(form Form) error
- func (f *Fullscreen) Begin(title string) func(error)
- func (f *Fullscreen) Heading(msg string)
- func (f *Fullscreen) Info(msg string)
- func (f *Fullscreen) Logs() io.Writer
- func (f *Fullscreen) OK(msg string)
- func (f *Fullscreen) Step(ctx context.Context, title string, fn func(context.Context) error) error
- func (f *Fullscreen) Warn(msg string)
- type Input
- type Option
- type Page
- type Plain
- func (p *Plain) Ask(form Form) error
- func (p *Plain) Begin(title string) func(error)
- func (p *Plain) Heading(msg string)
- func (p *Plain) Info(msg string)
- func (p *Plain) Logs() io.Writer
- func (p *Plain) OK(msg string)
- func (p *Plain) Step(ctx context.Context, title string, fn func(context.Context) error) error
- func (p *Plain) Warn(msg string)
- type UI
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQuit ends a flow without an error message. ErrQuit = errors.New("quit") // ErrAborted ends a flow because the user said no or cancelled a form. ErrAborted = errors.New("aborted") )
Functions ¶
func Confirm ¶
Confirm asks a yes/no question; description carries any warning, since a full-screen form hides the transcript.
func RunDiffViewer ¶ added in v0.1.5
func RunDiffViewer(ctx context.Context, s DiffSession) (*gitopsdiff.Report, error)
RunDiffViewer asks for a base if there is none, runs the diff and lets the user browse it full-screen. It returns the report, or nil when the user quit before it was ready.
func RunFullscreen ¶
func RunFullscreen(ctx context.Context, title string, out io.Writer, logPath string, flow func(context.Context, UI) error) error
RunFullscreen runs flow full-screen. After the app closes, everything except the raw installer logs is printed to out, and the full transcript is kept at logPath.
Types ¶
type Choices ¶
type Choices struct {
Key string
Title string
Description string
Options []Option
// Height limits the visible rows; 0 means the default.
Height int
Validate func([]string) error
Value *[]string
}
Choices asks for any number of Options.
type Confirmation ¶
Confirmation asks yes or no.
type DiffChoices ¶ added in v0.1.5
DiffChoices are the test cases and charts offered for a diff; Selected marks the default selection.
type DiffSelection ¶ added in v0.1.5
DiffSelection is what to render: empty TestCases or Charts mean the diff's defaults.
type DiffSession ¶ added in v0.1.5
type DiffSession struct {
Base string
Bases []string
Head string
// Choices lists the test cases and charts that can be rendered against base, the default selection selected;
// nil renders the defaults without asking.
Choices func(ctx context.Context, base string) (DiffChoices, error)
// Run computes the diff of the selection, reporting progress as it goes.
Run func(ctx context.Context, sel DiffSelection, progress func(gitopsdiff.Progress)) (*gitopsdiff.Report, error)
// Warnings returns what helm warned about while rendering, once Run returned.
Warnings func() string
}
DiffSession is what the diff viewer needs: the base to compare against (empty asks for one among Bases), the revision being compared, what can be rendered, and the diff itself.
type Field ¶
type Field interface {
// contains filtered or unexported methods
}
Field is one question: Input, Choice, Choices or Confirmation.
type Form ¶
type Form struct {
Pages []Page
}
Form is a set of questions asked together. Fields write the user's answers through their Value pointers, and the initial value of a pointer is the default answer. Plain and Fullscreen render it with huh; uitest answers it from a script.
type Fullscreen ¶
type Fullscreen struct {
// contains filtered or unexported fields
}
Fullscreen runs a flow in a goroutine and renders it as a full-screen app. Flow calls are turned into messages for the bubbletea program.
func (*Fullscreen) Ask ¶
func (f *Fullscreen) Ask(form Form) error
func (*Fullscreen) Begin ¶
func (f *Fullscreen) Begin(title string) func(error)
func (*Fullscreen) Heading ¶
func (f *Fullscreen) Heading(msg string)
func (*Fullscreen) Info ¶
func (f *Fullscreen) Info(msg string)
func (*Fullscreen) Logs ¶
func (f *Fullscreen) Logs() io.Writer
func (*Fullscreen) OK ¶
func (f *Fullscreen) OK(msg string)
func (*Fullscreen) Warn ¶
func (f *Fullscreen) Warn(msg string)
type Input ¶
type Input struct {
// Key identifies the field to scripted answers; it should be unique within a flow.
Key string
Title string
Description string
// DescriptionFunc replaces Description with text that depends on other answers; Watch is the variable it
// depends on (a pointer), so the text updates when that answer changes.
DescriptionFunc func() string
Watch any
// Secret hides what is typed.
Secret bool
Validate func(string) error
Value *string
}
Input asks for a line of text.
type Option ¶
type Option struct {
Label string
Value string
// Selected starts the option selected in a Choices field.
Selected bool
}
Option is one of the answers of a Choice or Choices field.
type Page ¶
type Page struct {
Title string
Description string
// Hidden skips the page when it returns true; it is evaluated when the page is reached, so it can depend
// on answers given on earlier pages.
Hidden func() bool
Fields []Field
}
Page is a group of fields shown together.
type Plain ¶
type Plain struct {
// contains filtered or unexported fields
}
func (*Plain) Heading ¶
Styled lines go through lipgloss.Fprintln, which drops the colors a non-terminal or a dumb terminal can't show.
type UI ¶
type UI interface {
// Ask shows the questions and returns ErrAborted when the user cancels.
Ask(form Form) error
Step(ctx context.Context, title string, fn func(context.Context) error) error
// Begin marks a long phase without a spinner (e.g. while logs stream); call end when it finishes.
Begin(title string) (end func(error))
Logs() io.Writer
Heading(msg string)
Info(msg string)
OK(msg string)
Warn(msg string)
}
UI is what the command flows talk to; Plain prints line by line, Fullscreen renders a full-screen app.