utils

package
v0.0.0-...-5d475a2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 17 Imported by: 0

README

utils package

Independent utilities with zero dependencies with other packages

Documentation

Index

Constants

View Source
const (
	TrueString  = "true"
	FalseString = "false"
	// These are used while comparing with runtime.GOOS
	// OsWindows represents the Windows operating system identifier
	OsWindows = "windows"
	// OsDarwin represents the macOS (Darwin) operating system identifier
	OsDarwin = "darwin"
	OsLinux  = "linux"
)

Variables

This section is empty.

Functions

func DirSize

func DirSize(path string) int64

Get directory total size TODO: Uni test this

func ExecuteCommand

func ExecuteCommand(timeLimit time.Duration, cmdDir string, baseCmd string, args ...string) (int, string, error)

func ExecuteCommandInShell

func ExecuteCommandInShell(timeLimit time.Duration, cmdDir string, shellCommand string) (int, string, error)

Choose correct shell as per OS

func FooterWidth

func FooterWidth(fullWidth int) int

We have three panels, so 6 characters for border <---><---><---> Hence we have (fullWidth - 6) / 3 = fullWidth/3 - 2

func FullFooterHeight

func FullFooterHeight(footerHeight int, toggleFooter bool) int

Including borders

func FzfSearch

func FzfSearch(query string, source []string) []fzf.MatchResult

Returning a string slice causes inefficiency in current usage

func LoadTomlFile

func LoadTomlFile(filePath string, defaultData string, target interface{}, fixFlag bool) error

Helper function to load and validate TOML files with field checking errorPrefix is appended before every error message

func MergeTomlContent

func MergeTomlContent(defaultContent []byte, existingPath string) ([]byte, error)

MergeTomlContent merges default TOML content with existing file content. User values are preserved, new fields from default are added. Returns the merged TOML content as bytes.

func PrintfAndExit

func PrintfAndExit(format string, args ...any)

Print formatted output line to stderr and exit with status 1 Cannot use log.Fataln() as slog.SetDefault() causes those lines to go into log file

func PrintlnAndExit

func PrintlnAndExit(args ...any)

Print line to stderr and exit with status 1 Cannot use log.Fataln() as slog.SetDefault() causes those lines to go into log file

func ReadBoolFile

func ReadBoolFile(path string, defaultValue bool) bool

Read file with "true" / "false" as content. In case of issues, return defaultValue

func ResolveAbsPath

func ResolveAbsPath(currentDir string, path string) string

If path is not absolute, then append to currentDir and get absolute path Resolve paths starting with "~" currentDir should be an absolute path

func SetRootLoggerToDiscarded

func SetRootLoggerToDiscarded()

Used in unit test

func SetRootLoggerToStdout

func SetRootLoggerToStdout(debug bool)

Used in unit test

func TeaRuneKeyMsg

func TeaRuneKeyMsg(msg string) tea.KeyMsg

func WriteBoolFile

func WriteBoolFile(path string, value bool) error

func WriteTomlData

func WriteTomlData(filePath string, data interface{}) error

Types

type MissingFieldIgnorer

type MissingFieldIgnorer interface {
	GetIgnoreMissingFields() bool
}

MissingFieldIgnorer defines the interface for configuration types that can ignore missing fields during TOML file loading. Types implementing this interface can control whether missing field warnings are suppressed when parsing configuration files.

type TestTOMLMissingIgnorerType

type TestTOMLMissingIgnorerType struct {
	SampleBool    bool     `toml:"sample_bool"`
	SampleInt     int      `toml:"sample_int"`
	SampleStr     string   `toml:"sample_str"`
	SampleSlice   []string `toml:"sample_slice"`
	IgnoreMissing bool     `toml:"ignore_missing"`
}

func (TestTOMLMissingIgnorerType) GetIgnoreMissingFields

func (t TestTOMLMissingIgnorerType) GetIgnoreMissingFields() bool

func (TestTOMLMissingIgnorerType) WithIgnoreMissing

type TestTOMLType

type TestTOMLType struct {
	SampleBool  bool     `toml:"sample_bool"`
	SampleInt   int      `toml:"sample_int"`
	SampleStr   string   `toml:"sample_str"`
	SampleSlice []string `toml:"sample_slice"`
}

type TomlLoadError

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

func NewTomlLoadError

func NewTomlLoadError(msg string, wrapped error, fatal bool, missing bool) *TomlLoadError

func (*TomlLoadError) AddMessageAndError

func (t *TomlLoadError) AddMessageAndError(msg string, err error)

Include another msg. For now we dont need to have this as wrapped error.

func (*TomlLoadError) Error

func (t *TomlLoadError) Error() string

func (*TomlLoadError) IsFatal

func (t *TomlLoadError) IsFatal() bool

func (*TomlLoadError) MissingFields

func (t *TomlLoadError) MissingFields() bool

func (*TomlLoadError) Unwrap

func (t *TomlLoadError) Unwrap() error

func (*TomlLoadError) UpdateMessageAndError

func (t *TomlLoadError) UpdateMessageAndError(msg string, err error)

Jump to

Keyboard shortcuts

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