Documentation
¶
Index ¶
- func ColorEnabled(ctx context.Context) bool
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Err(ctx context.Context) io.Writer
- func ErrPrint(ctx context.Context, s string)
- func ErrPrintf(ctx context.Context, format string, a ...any)
- func ErrPrintln(ctx context.Context, a ...any)
- func FromCmd(ctx context.Context, cmd *cobra.Command, configTheme string) context.Context
- func In(ctx context.Context) io.Reader
- func Indent(s, indent string) string
- func IsInteractive(ctx context.Context) bool
- func IsTerminal(ctx context.Context) bool
- func IsValidTheme(theme string) bool
- func Out(ctx context.Context) io.Writer
- func Print(ctx context.Context, v string)
- func PrintJSON(ctx context.Context, v any) error
- func PrintJSONFromReader(ctx context.Context, r io.Reader) error
- func PrintMarkdown(ctx context.Context, md string)
- func Printf(ctx context.Context, format string, a ...any)
- func Println(ctx context.Context, a ...any)
- func PromptSecret(ctx context.Context, header string) (string, error)
- func PromptSelect(ctx context.Context, prompt string, options []string) (int, error)
- func PromptSelectDefault(ctx context.Context, prompt string, options []string, defaultIdx int) (int, error)
- func PromptText(ctx context.Context, header, placeholder string, defaultVal ...string) (string, error)
- func ReadSecret(ctx context.Context, value string) (string, error)
- func SymbolFail(ctx context.Context) string
- func SymbolOK(ctx context.Context) string
- func SymbolWarn(ctx context.Context) string
- func Testing(ctx context.Context) context.Context
- func Title(ctx context.Context, strs ...string) string
- func ValidThemes() []string
- func WithJQFilter(ctx context.Context, jqFilter string) context.Context
- func WithStreams(ctx context.Context, s Streams) context.Context
- type Spin
- type Streams
- func (s Streams) ColorEnabled() bool
- func (s Streams) Confirm(ctx context.Context, prompt string) bool
- func (s Streams) DebugContext(ctx context.Context, msg string, args ...any)
- func (s Streams) ErrPrint(str string)
- func (s Streams) ErrPrintf(format string, a ...any)
- func (s Streams) ErrPrintln(a ...any)
- func (s Streams) IsInteractive() bool
- func (s Streams) IsTerminal() bool
- func (s Streams) Print(v string)
- func (s Streams) PrintJSON(ctx context.Context, v any) error
- func (s Streams) PrintJSONFromReader(ctx context.Context, r io.Reader) error
- func (s Streams) PrintMarkdown(md string)
- func (s Streams) Printf(format string, a ...any)
- func (s Streams) Println(a ...any)
- func (s Streams) PromptSecret(ctx context.Context, header string) (string, error)
- func (s Streams) PromptSelect(ctx context.Context, prompt string, options []string) (int, error)
- func (s Streams) PromptSelectDefault(ctx context.Context, prompt string, options []string, defaultIdx int) (int, error)
- func (s Streams) ReadSecret(value string) (string, error)
- func (s Streams) RenderMarkdown(md string) (string, error)
- func (s Streams) Spinner(active bool, msg string) *Spin
- func (s Streams) SymbolError(strs ...string) string
- func (s Streams) SymbolSuccess(strs ...string) string
- func (s Streams) SymbolWarning(strs ...string) string
- func (s Streams) Title(strs ...string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorEnabled ¶
func ErrPrintln ¶
func FromCmd ¶
FromCmd extracts Streams from a cobra.Command's Out/Err/In and reads the --quiet persistent flag if registered on the root command.
The color theme is resolved with the --theme flag taking precedence when it was explicitly set; otherwise configTheme (the stored CLI setting, "" if none) is used, falling back to the flag's "auto" default.
func IsInteractive ¶
func IsTerminal ¶
func IsValidTheme ¶
IsValidTheme reports whether theme is one of the names returned by ValidThemes.
func PrintMarkdown ¶
func PromptSecret ¶
PromptSecret presents a masked text input to collect a secret value. Returns ("", nil) if the user cancels.
func PromptSelect ¶
PromptSelect presents an interactive single-choice list to the user and returns the index of the selected option. Returns (-1, nil) if the user cancels with esc or ctrl+c.
func PromptSelectDefault ¶
func PromptSelectDefault(ctx context.Context, prompt string, options []string, defaultIdx int) (int, error)
PromptSelectDefault is like PromptSelect but pre-highlights the option at defaultIdx. Returns the index of the selected option, or -1 if cancelled.
func PromptText ¶
func PromptText(ctx context.Context, header, placeholder string, defaultVal ...string) (string, error)
PromptText presents a plain (non-secret) single-line text input via bubbletea. header is the bold heading above the input; placeholder is shown inside the empty field; defaultVal (optional) is returned when the user presses Enter with an empty field. Returns ("", nil) if the user cancels with esc or ctrl+c.
func ReadSecret ¶
ReadSecret reads a sensitive value from the streams in context. Returns value as-is unless value is "-", in which case reads one line from stdin.
func SymbolFail ¶
func SymbolWarn ¶
func ValidThemes ¶
func ValidThemes() []string
ValidThemes returns the theme names accepted by the --theme flag and the "theme" CLI setting, sorted for stable display. This is the single source of truth for theme validation: "auto" detects the terminal background, "ansi" is our custom 16-color style, and the rest are glamour's built-in styles.
Types ¶
type Spin ¶
type Spin struct {
// contains filtered or unexported fields
}
Spin is a progress indicator. Call Stop when the operation completes. It is safe to call Stop on a nil or no-op Spin, and safe to call it more than once.
type Streams ¶
type Streams struct {
Out io.Writer // structured output (data results)
Err io.Writer // status messages, errors, progress
In io.Reader // user input for interactive prompts
Quiet bool // when true, ErrPrintf/ErrPrintln produce no output
// contains filtered or unexported fields
}
Streams bundles the I/O channels passed through every command. All output must go through Streams — never write to os.Stdout directly.
func Get ¶
Get returns the Streams stored in ctx, or a discard-everything Streams if none was set. Use this when you need to pass a Streams value to a helper function (e.g. cmdutil.ConfirmOrForce) rather than calling the ctx-based package-level wrappers.
func (Streams) ColorEnabled ¶
ColorEnabled reports whether color and Unicode symbols should be used. False when: not a TTY, NO_COLOR set, CIRCLE_NO_COLOR set, or TERM=dumb.
func (Streams) Confirm ¶
Confirm presents a y/N confirmation prompt via bubbletea. Returns true only if the user presses y/Y. Returns false on n/N, esc, ctrl+c, enter, or any program error — the safe answer is always No.
func (Streams) DebugContext ¶
func (Streams) ErrPrintln ¶
ErrPrintln writes a line to Err. No-op when Quiet is true.
func (Streams) IsInteractive ¶
IsInteractive reports whether the session can support interactive prompts. False when: not a TTY, CI=true (running in a CI environment), or CIRCLE_NO_INTERACTIVE is set.
func (Streams) IsTerminal ¶
IsTerminal reports whether Out is a terminal (i.e. a human is watching).
func (Streams) PrintJSONFromReader ¶
func (Streams) PrintMarkdown ¶
PrintMarkdown renders md and writes the result to Out. When Out is an interactive terminal and the rendered output is taller than the screen, it is shown in a scrollable full-screen viewport instead. Falls back to writing raw markdown on render error.
func (Streams) PromptSecret ¶
PromptSecret presents a masked text input via bubbletea to collect a secret value. header is displayed above the input field (e.g. "Enter value for MY_VAR"). Returns ("", nil) if the user cancels with esc or ctrl+c.
func (Streams) PromptSelect ¶
PromptSelect presents a bubbletea single-choice list prompt. Returns the selected index, or -1 if the user cancels.
func (Streams) PromptSelectDefault ¶
func (s Streams) PromptSelectDefault(ctx context.Context, prompt string, options []string, defaultIdx int) (int, error)
PromptSelectDefault is like PromptSelect but starts the cursor on defaultIdx (clamped to the options) so a default choice is pre-highlighted.
func (Streams) ReadSecret ¶
ReadSecret returns value as-is, unless value is "-", in which case it reads one line from In. Use this for flags or arguments that accept sensitive values (tokens, passwords, secrets) to allow callers to pipe the value in without exposing it in shell history or process listings:
echo "mytoken" | circleci setting set token -
func (Streams) RenderMarkdown ¶
RenderMarkdown renders md as styled markdown when color is enabled, falling back to the raw string when output is not a TTY or color is disabled. The rendered string is returned; use PrintMarkdown to write it to Out.
func (Streams) Spinner ¶
Spinner creates and starts a progress indicator for msg.
Pass active=false (e.g. !jsonOut) to get a no-op Spin with no output. When quiet mode is on, the Spin is also a no-op. In a non-interactive session (no TTY, CI=true, spinner disabled) a plain "msg...\n" line is written to stderr instead of animating.
Always call Stop() when the operation completes.