output

package
v1.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const DefaultLogLines = 20

DefaultLogLines is the default number of lines to read from log files.

Variables

View Source
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 Bold deprecated

func Bold(format string, args ...interface{})

Bold prints a bold message using the default logger.

Deprecated: Use (*Logger).Bold() with an injected logger instead.

func ColoredSeparator

func ColoredSeparator(c *color.Color) string

ColoredSeparator returns a colored separator line.

func ConfirmPrompt

func ConfirmPrompt(message string) (bool, error)

ConfirmPrompt asks for user confirmation and returns true if confirmed.

func ConfirmPromptDefault

func ConfirmPromptDefault(message string, defaultYes bool) (bool, error)

ConfirmPromptDefault asks for confirmation with a default value.

func Cyan deprecated

func Cyan(format string, args ...interface{})

Cyan prints a cyan message using the default logger.

Deprecated: Use (*Logger).Cyan() with an injected logger instead.

func CyanSeparator

func CyanSeparator() string

CyanSeparator returns a cyan separator line for info.

func Debug deprecated

func Debug(format string, args ...interface{})

Debug prints a debug message using the default logger.

Deprecated: Use (*Logger).Debug() with an injected logger instead.

func Error deprecated

func Error(format string, args ...interface{})

Error prints an error message using the default logger.

Deprecated: Use (*Logger).Error() with an injected logger instead.

func Info deprecated

func Info(format string, args ...interface{})

Info prints an informational message using the default logger.

Deprecated: Use (*Logger).Info() with an injected logger instead.

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

func ReadLastLines(filePath string, n int) ([]string, error)

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

func SelectPrompt(message string, options []string) (int, error)

SelectPrompt asks user to select from a list of options.

func Separator

func Separator() string

Separator returns a separator line of the default width.

func StringPrompt

func StringPrompt(message string) (string, error)

StringPrompt asks for a string input.

func StringPromptDefault

func StringPromptDefault(message, defaultValue string) (string, error)

StringPromptDefault asks for a string input with a default value.

func Success deprecated

func Success(format string, args ...interface{})

Success prints a success message using the default logger.

Deprecated: Use (*Logger).Success() with an injected logger instead.

func Warn deprecated

func Warn(format string, args ...interface{})

Warn prints a warning message using the default logger.

Deprecated: Use (*Logger).Warn() with an injected logger instead.

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 NewLogger

func NewLogger() *Logger

NewLogger creates a new Logger instance.

func (*Logger) Bold

func (l *Logger) Bold(format string, args ...interface{})

Bold prints a message in bold.

func (*Logger) Cyan

func (l *Logger) Cyan(format string, args ...interface{})

Cyan prints a message in cyan (for highlights).

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug prints a debug message if verbose mode is enabled.

func (*Logger) ErrWriter

func (l *Logger) ErrWriter() io.Writer

ErrWriter returns the underlying writer for stderr.

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error prints an error message in red.

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info prints an informational message in default color. If autoSpinner is enabled, a spinner will be shown after the message.

func (*Logger) IsVerbose

func (l *Logger) IsVerbose() bool

IsVerbose returns whether verbose mode is enabled.

func (*Logger) Print

func (l *Logger) Print(format string, args ...interface{})

Print prints a plain message without newline.

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) Println

func (l *Logger) Println(format string, args ...interface{})

Println prints a plain message with newline.

func (*Logger) Progress

func (l *Logger) Progress(downloaded, total int64, speed float64)

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

func (l *Logger) SetAutoSpinner(enabled bool)

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

func (l *Logger) SetJSONMode(jsonMode bool)

SetJSONMode enables JSON output mode (suppresses text output).

func (*Logger) SetNoColor

func (l *Logger) SetNoColor(noColor bool)

SetNoColor disables colored output.

func (*Logger) SetVerbose

func (l *Logger) SetVerbose(verbose bool)

SetVerbose enables verbose logging.

func (*Logger) StartSpinner

func (l *Logger) StartSpinner(message string)

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

func (l *Logger) Success(format string, args ...interface{})

Success prints a success message in green with checkmark. If autoSpinner is enabled, a spinner will be shown after the message.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

Warn prints a warning message in yellow.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the underlying writer for stdout. This can be used to pass to external commands.

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

func NewProgress(total int) *Progress

NewProgress creates a new Progress instance with the given total steps.

func (*Progress) Current

func (p *Progress) Current() int

Current returns the current step number.

func (*Progress) Done

func (p *Progress) Done(message string)

Done prints a completion message.

func (*Progress) Reset

func (p *Progress) Reset()

Reset resets the progress counter.

func (*Progress) SetJSONMode

func (p *Progress) SetJSONMode(jsonMode bool)

SetJSONMode enables JSON output mode (suppresses text output).

func (*Progress) SetNoColor

func (p *Progress) SetNoColor(noColor bool)

SetNoColor disables colored output.

func (*Progress) SetTotal

func (p *Progress) SetTotal(total int)

SetTotal updates the total number of steps.

func (*Progress) Stage

func (p *Progress) Stage(description string)

Stage prints a progress stage message in format N/M Description...

func (*Progress) StageWithNumber

func (p *Progress) StageWithNumber(step int, description string)

StageWithNumber prints a progress stage with explicit step number.

func (*Progress) Total

func (p *Progress) Total() int

Total returns the total number of steps.

type Spinner

type Spinner struct {
	// contains filtered or unexported fields
}

Spinner represents a simple spinner for indeterminate progress.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new Spinner with the given message.

func (*Spinner) SetJSONMode

func (s *Spinner) SetJSONMode(jsonMode bool)

SetJSONMode enables JSON output mode.

func (*Spinner) SetNoColor

func (s *Spinner) SetNoColor(noColor bool)

SetNoColor disables colored output.

func (*Spinner) Start

func (s *Spinner) Start()

Start prints the spinner message (simplified - no animation in CLI).

func (*Spinner) Stop

func (s *Spinner) Stop(success bool)

Stop stops the spinner and prints done.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(message string, success bool)

StopWithMessage stops the spinner with a custom message.

Jump to

Keyboard shortcuts

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