util

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package util contains shared helpers used by CLI command subpackages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSelector

func BuildSelector(id, idPrefix, hostContains, pathContains, headContains, olderThan, health string) (session.Selector, error)

BuildSelector builds a session selector from common flags.

func IsTerminalWriter

func IsTerminalWriter(out io.Writer) bool

IsTerminalWriter reports whether out is a TTY char device.

func MarshalPrettyJSON

func MarshalPrettyJSON(v any) ([]byte, error)

MarshalPrettyJSON marshals v with multiline indentation.

func ParseHealth

func ParseHealth(v string) (session.Health, error)

ParseHealth parses health flag value.

func ResolveOrDefault

func ResolveOrDefault(v string, fallback func() (string, error)) (string, error)

ResolveOrDefault resolves an explicit path or uses fallback.

func ShouldUseColor

func ShouldUseColor(mode string, out io.Writer) bool

ShouldUseColor decides output coloring.

func StripANSI

func StripANSI(v string) string

StripANSI removes ANSI SGR sequences.

func WithExitCode

func WithExitCode(err error, code int) error

WithExitCode wraps an error with a process exit code for main() handling.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, mode os.FileMode) error

WriteFileAtomic writes data by temp file + rename.

Types

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError carries a user-facing error plus an intended process exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

Error implements error.

func (*ExitError) ExitCode

func (e *ExitError) ExitCode() int

ExitCode returns Code, defaulting to 1 for nil or invalid values.

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Unwrap returns the wrapped error.

Jump to

Keyboard shortcuts

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