Documentation
¶
Index ¶
- Constants
- func Env(desc, envVar string) string
- func PromptPassword(prompt string) (string, error)
- func PromptPasswordConfirm(msg string) (string, error)
- func Style(color, text string) string
- type ConsoleReporter
- type Detail
- type NoOpReporter
- type Phase
- type Reporter
- type SafeLogWriter
- type TermWriter
- func (t TermWriter) Blank()
- func (t TermWriter) Command(name, args string)
- func (t TermWriter) Commands(cmds [][2]string)
- func (t TermWriter) Examples(cmds ...string)
- func (t TermWriter) Flags(flags [][2]string)
- func (t TermWriter) Heading(title string)
- func (t TermWriter) HeadingSub(title, subtitle string)
- func (t TermWriter) Note(lines ...string)
Constants ¶
const ( Bold = logger.ColorBold Dim = logger.ColorDim Red = logger.ColorRed Cyan = logger.ColorCyan Green = logger.ColorGreen Yellow = logger.ColorYellow Reset = logger.ColorReset )
Variables ¶
This section is empty.
Functions ¶
func PromptPassword ¶ added in v1.4.1
PromptPassword prompts the user for a password on the terminal without echoing.
func PromptPasswordConfirm ¶ added in v1.9.0
PromptPasswordConfirm prompts for a password and then a confirmation. Returns an error if they don't match or are empty.
Types ¶
type ConsoleReporter ¶
type ConsoleReporter struct {
// contains filtered or unexported fields
}
ConsoleReporter implements Reporter using go-pretty for console output.
func NewConsoleReporter ¶
func NewConsoleReporter() *ConsoleReporter
func (*ConsoleReporter) SetDetail ¶ added in v1.18.0
func (c *ConsoleReporter) SetDetail(d Detail)
SetDetail chooses how much this reporter shows.
This is the single place verbosity is decided. Operations report what they are doing at a level; this decides which levels reach the user. Before it existed, each of the nine operations carried its own verbose option and gated its own log calls, so the same choice had nine names and nine implementations.
func (*ConsoleReporter) SetLogWriter ¶
func (c *ConsoleReporter) SetLogWriter(w *SafeLogWriter)
SetLogWriter registers a SafeLogWriter that will be kept in sync with the active progress writer so external log lines (e.g. store debug output) render cleanly above the progress bar.
func (*ConsoleReporter) StartPhase ¶
func (c *ConsoleReporter) StartPhase(name string, total int64, isBytes bool) Phase
type Detail ¶ added in v1.18.0
type Detail int
Detail is how much an operation should say about what it is doing.
It exists because verbosity is a presentation choice, and the code that makes presentation choices is the reporter — not the engine producing the events. Every operation used to carry its own verbose flag and gate its own log calls, which meant six option constructors for one idea and six places to change it.
const ( // DetailNormal reports milestones: phases, counts, warnings. DetailNormal Detail = iota // DetailVerbose additionally reports per-item progress — every object // verified, every file restored. On a large repository this is a line per // object, which is why it is off by default and why Logf defers formatting. DetailVerbose )
type NoOpReporter ¶
type NoOpReporter struct{}
NoOpReporter implements Reporter doing nothing (for tests or silent mode).
func NewNoOpReporter ¶
func NewNoOpReporter() *NoOpReporter
func (*NoOpReporter) StartPhase ¶
func (n *NoOpReporter) StartPhase(name string, total int64, isBytes bool) Phase
type Phase ¶
type Phase interface {
Increment(n int64)
// Log records a message the caller has already decided to emit.
Log(msg string)
// Logf records a message at a detail level, formatting the arguments only
// if the reporter wants that level.
//
// The deferral is the point, not an optimization detail: per-item logging
// runs once per object checked or file restored, so formatting a string the
// reporter will discard is work proportional to repository size.
Logf(level Detail, format string, args ...any)
Done()
Error()
}
Phase represents an active progress tracking phase.
type Reporter ¶
type Reporter interface {
// StartPhase starts a new progress tracking phase.
// name: Description of the phase.
// total: Total items/bytes to process. 0 for indeterminate.
// isBytes: If true, units are bytes, otherwise count.
StartPhase(name string, total int64, isBytes bool) Phase
}
Reporter defines the interface for progress reporting.
type SafeLogWriter ¶
type SafeLogWriter struct {
// contains filtered or unexported fields
}
SafeLogWriter is an io.Writer that coexists with go-pretty progress bars. When a progress writer is active, lines are routed through pw.Log() so they render above the bar. Otherwise lines go straight to stderr.
func (*SafeLogWriter) ClearActive ¶
func (w *SafeLogWriter) ClearActive()
ClearActive unregisters the progress writer.
func (*SafeLogWriter) SetActive ¶
func (w *SafeLogWriter) SetActive(pw progress.Writer)
SetActive registers the progress writer that is currently rendering.
type TermWriter ¶
TermWriter provides helpers for styled terminal output.
func NewTermWriter ¶
func NewTermWriter(w io.Writer) TermWriter
NewTermWriter returns a TermWriter targeting the given writer.
func (TermWriter) Blank ¶
func (t TermWriter) Blank()
func (TermWriter) Command ¶
func (t TermWriter) Command(name, args string)
func (TermWriter) Commands ¶
func (t TermWriter) Commands(cmds [][2]string)
func (TermWriter) Examples ¶
func (t TermWriter) Examples(cmds ...string)
func (TermWriter) Flags ¶
func (t TermWriter) Flags(flags [][2]string)
func (TermWriter) Heading ¶
func (t TermWriter) Heading(title string)
func (TermWriter) HeadingSub ¶
func (t TermWriter) HeadingSub(title, subtitle string)
func (TermWriter) Note ¶
func (t TermWriter) Note(lines ...string)