Documentation
¶
Index ¶
- Constants
- Variables
- func Bold(format string, args ...interface{})deprecated
- func ColoredSeparator(c *color.Color) string
- func ConfirmPrompt(message string) (bool, error)
- func ConfirmPromptDefault(message string, defaultYes bool) (bool, error)
- func Cyan(format string, args ...interface{})deprecated
- func CyanSeparator() string
- func Debug(format string, args ...interface{})deprecated
- func Error(format string, args ...interface{})deprecated
- func Info(format string, args ...interface{})deprecated
- func PrintCommandErrorDefault(info *CommandErrorInfo)
- func PrintNodeErrorDefault(info *NodeErrorInfo)
- func ReadLastLines(filePath string, n int) ([]string, error)
- func RedSeparator() string
- func SelectPrompt(message string, options []string) (int, error)
- func Separator() string
- func StringPrompt(message string) (string, error)
- func StringPromptDefault(message, defaultValue string) (string, error)
- func Success(format string, args ...interface{})deprecated
- func Warn(format string, args ...interface{})deprecated
- func YellowSeparator() string
- type CommandErrorInfo
- type EmptyFileError
- type FileNotFoundError
- type Logger
- func (l *Logger) Bold(format string, args ...interface{})
- func (l *Logger) Cyan(format string, args ...interface{})
- func (l *Logger) Debug(format string, args ...interface{})
- func (l *Logger) ErrWriter() io.Writer
- func (l *Logger) Error(format string, args ...interface{})
- func (l *Logger) Info(format string, args ...interface{})
- func (l *Logger) IsVerbose() bool
- func (l *Logger) Print(format string, args ...interface{})
- func (l *Logger) PrintCommandError(info *CommandErrorInfo)
- func (l *Logger) PrintNodeError(info *NodeErrorInfo)
- func (l *Logger) Println(format string, args ...interface{})
- func (l *Logger) Progress(downloaded, total int64, speed float64)
- func (l *Logger) ProgressComplete()
- func (l *Logger) SetAutoSpinner(enabled bool)
- func (l *Logger) SetJSONMode(jsonMode bool)
- func (l *Logger) SetNoColor(noColor bool)
- func (l *Logger) SetVerbose(verbose bool)
- func (l *Logger) StartSpinner(message string)
- func (l *Logger) StopSpinner()
- func (l *Logger) Success(format string, args ...interface{})
- func (l *Logger) Warn(format string, args ...interface{})
- func (l *Logger) Writer() io.Writer
- type LoggerInterface
- type NodeErrorInfo
- type PermissionDeniedError
- type Progress
- func (p *Progress) Current() int
- func (p *Progress) Done(message string)
- func (p *Progress) Reset()
- func (p *Progress) SetJSONMode(jsonMode bool)
- func (p *Progress) SetNoColor(noColor bool)
- func (p *Progress) SetTotal(total int)
- func (p *Progress) Stage(description string)
- func (p *Progress) StageWithNumber(step int, description string)
- func (p *Progress) Total() int
- type Spinner
Constants ¶
const ( // SeparatorWidth is the width of separator lines. SeparatorWidth = 60 // SeparatorChar is the character used for separator lines. SeparatorChar = "─" )
Visual separator constants for error output formatting.
const DefaultLogLines = 20
DefaultLogLines is the default number of lines to read from log files.
Variables ¶
var DefaultLogger = NewLogger()
DefaultLogger is the package-level default logger instance.
Deprecated: DefaultLogger is provided for backward compatibility. New code should use dependency injection by passing *Logger through constructors or configuration structs. Use NewLogger() to create a new logger instance instead of relying on this global.
Functions ¶
func ColoredSeparator ¶
ColoredSeparator returns a colored separator line.
func ConfirmPrompt ¶
ConfirmPrompt asks for user confirmation and returns true if confirmed.
func ConfirmPromptDefault ¶
ConfirmPromptDefault asks for confirmation with a default value.
func CyanSeparator ¶
func CyanSeparator() string
CyanSeparator returns a cyan separator line for info.
func PrintCommandErrorDefault ¶
func PrintCommandErrorDefault(info *CommandErrorInfo)
PrintCommandErrorDefault prints command error using the default logger.
func PrintNodeErrorDefault ¶
func PrintNodeErrorDefault(info *NodeErrorInfo)
PrintNodeErrorDefault prints node error using the default logger.
func ReadLastLines ¶
ReadLastLines reads the last n lines from a file. Returns empty slice if file doesn't exist or is empty. Returns appropriate error messages for edge cases.
func RedSeparator ¶
func RedSeparator() string
RedSeparator returns a red separator line for errors.
func SelectPrompt ¶
SelectPrompt asks user to select from a list of options.
func StringPrompt ¶
StringPrompt asks for a string input.
func StringPromptDefault ¶
StringPromptDefault asks for a string input with a default value.
func YellowSeparator ¶
func YellowSeparator() string
YellowSeparator returns a yellow separator line for warnings.
Types ¶
type CommandErrorInfo ¶
type CommandErrorInfo struct {
Command string // Full command that was executed
Args []string // Command arguments
WorkDir string // Working directory
Stdout string // Standard output content
Stderr string // Standard error content
ExitCode int // Exit code
Error error // The error that occurred
}
CommandErrorInfo contains error information for a failed external command.
type EmptyFileError ¶
type EmptyFileError struct {
Path string
}
EmptyFileError indicates the log file is empty.
func (*EmptyFileError) Error ¶
func (e *EmptyFileError) Error() string
type FileNotFoundError ¶
type FileNotFoundError struct {
Path string
}
FileNotFoundError indicates the log file does not exist.
func (*FileNotFoundError) Error ¶
func (e *FileNotFoundError) Error() string
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides colored output functions for CLI feedback.
func (*Logger) Info ¶
Info prints an informational message in default color. If autoSpinner is enabled, a spinner will be shown after the message.
func (*Logger) PrintCommandError ¶
func (l *Logger) PrintCommandError(info *CommandErrorInfo)
PrintCommandError prints formatted error information for a failed command. In default mode: prints command and stderr output. In verbose mode: also prints work directory, stdout, and exit code.
func (*Logger) PrintNodeError ¶
func (l *Logger) PrintNodeError(info *NodeErrorInfo)
PrintNodeError prints formatted error information for a failed node. Includes log file contents and contextual information. In default mode: prints node name, log path, and log contents. In verbose mode: also prints command, work directory, and PID.
func (*Logger) Progress ¶
Progress prints a progress bar on the same line (uses carriage return). downloaded and total are in bytes. speed is in bytes per second.
func (*Logger) ProgressComplete ¶
func (l *Logger) ProgressComplete()
ProgressComplete finishes the progress bar and moves to a new line.
func (*Logger) SetAutoSpinner ¶
SetAutoSpinner enables or disables automatic spinner after Success/Info logs. When enabled, a spinner will be shown after each Success or Info log to indicate ongoing work. The spinner is automatically cleared when the next log is printed.
func (*Logger) SetJSONMode ¶
SetJSONMode enables JSON output mode (suppresses text output).
func (*Logger) SetNoColor ¶
SetNoColor disables colored output.
func (*Logger) SetVerbose ¶
SetVerbose enables verbose logging.
func (*Logger) StartSpinner ¶
StartSpinner starts an animated spinner with a message. The spinner runs in a background goroutine until StopSpinner is called.
func (*Logger) StopSpinner ¶
func (l *Logger) StopSpinner()
StopSpinner stops the spinner and clears the spinner line.
func (*Logger) Success ¶
Success prints a success message in green with checkmark. If autoSpinner is enabled, a spinner will be shown after the message.
type LoggerInterface ¶
type LoggerInterface interface {
// Core logging methods
Info(format string, args ...interface{})
Warn(format string, args ...interface{})
Error(format string, args ...interface{})
Debug(format string, args ...interface{})
Success(format string, args ...interface{})
// Output methods
Print(format string, args ...interface{})
Println(format string, args ...interface{})
Bold(format string, args ...interface{})
Cyan(format string, args ...interface{})
// Configuration methods
SetVerbose(verbose bool)
SetNoColor(noColor bool)
SetJSONMode(jsonMode bool)
IsVerbose() bool
// Writer access
Writer() io.Writer
ErrWriter() io.Writer
// Error info printing
PrintNodeError(info *NodeErrorInfo)
PrintCommandError(info *CommandErrorInfo)
}
LoggerInterface defines the logging interface for services. This allows for dependency injection and easier testing.
type NodeErrorInfo ¶
type NodeErrorInfo struct {
NodeName string // Node identifier (e.g., "node0", "node1")
NodeDir string // Node home directory path
LogPath string // Full path to log file
LogLines []string // Last N lines from log file
Error error // The error that occurred
Command string // Executed command (for verbose mode)
WorkDir string // Working directory (for verbose mode)
PID int // Process ID (if available)
}
NodeErrorInfo contains error information for a failed node.
type PermissionDeniedError ¶
type PermissionDeniedError struct {
Path string
}
PermissionDeniedError indicates the log file cannot be read due to permissions.
func (*PermissionDeniedError) Error ¶
func (e *PermissionDeniedError) Error() string
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress provides progress indication for multi-step operations.
func NewProgress ¶
NewProgress creates a new Progress instance with the given total steps.
func (*Progress) SetJSONMode ¶
SetJSONMode enables JSON output mode (suppresses text output).
func (*Progress) SetNoColor ¶
SetNoColor disables colored output.
func (*Progress) StageWithNumber ¶
StageWithNumber prints a progress stage with explicit step number.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner represents a simple spinner for indeterminate progress.
func NewSpinner ¶
NewSpinner creates a new Spinner with the given message.
func (*Spinner) SetJSONMode ¶
SetJSONMode enables JSON output mode.
func (*Spinner) SetNoColor ¶
SetNoColor disables colored output.
func (*Spinner) Start ¶
func (s *Spinner) Start()
Start prints the spinner message (simplified - no animation in CLI).
func (*Spinner) StopWithMessage ¶
StopWithMessage stops the spinner with a custom message.