internal

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogQuiet   = 0
	LogNormal  = 1
	LogVerbose = 2
	LogDebug   = 3
)

Verbosity levels

View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorCyan   = "\033[36m"
)

ANSI color codes

View Source
const Version = "0.1.14"

Version is the current version of git-tree-go

Variables

This section is empty.

Functions

func CommonPrefix

func CommonPrefix(paths []string, allowRootMatch bool) string

CommonPrefix returns the longest path prefix that is a prefix of all paths in the array. If the array is empty, return ”. If only the leading slash matches and allowRootMatch is true, return '/', else return ”.

func DerefSymlink(symlink string) (string, error)

DerefSymlink returns the real path of a symlink.

func EnsureEndsWith

func EnsureEndsWith(str, suffix string) string

EnsureEndsWith ensures that a string ends with the specified suffix.

func ExpandEnv

func ExpandEnv(str string) string

ExpandEnv expands environment variables in a string. Supports $VAR, ${VAR}, and %VAR% formats.

func GetVerbosity

func GetVerbosity() int

GetVerbosity returns the current verbosity level from the default logger.

func Log

func Log(level int, message string, color string)

Log logs a message using the default logger.

func LogStdout

func LogStdout(message string)

LogStdout logs to stdout using the default logger.

func ResetLogger added in v0.1.12

func ResetLogger()

ResetLogger resets the default logger (primarily for testing).

func Roots

func Roots(paths []string, level int, allowRootMatch bool) string

Roots returns the common root directory for the given paths up to the specified level. Level is 1-indexed (minimum # of leading directory names in result).

func SetVerbosity

func SetVerbosity(level int)

SetVerbosity sets the verbosity level on the default logger.

func ShutdownLogger

func ShutdownLogger()

ShutdownLogger shuts down the default logger.

Types

type AbstractCommand

type AbstractCommand struct {
	Config         *Config
	Args           []string
	Serial         bool
	AllowEmptyArgs bool
}

AbstractCommand provides common functionality for all git-tree commands.

func NewAbstractCommand

func NewAbstractCommand(args []string, allowEmptyArgs bool) *AbstractCommand

NewAbstractCommand creates a new AbstractCommand instance.

func (*AbstractCommand) ParseCommonFlags

func (cmd *AbstractCommand) ParseCommonFlags(helpFunc func()) []string

ParseCommonFlags parses common flags like -h, -q, -s. Returns the remaining non-flag arguments.

func (*AbstractCommand) ParseFlagsWithCallback

func (cmd *AbstractCommand) ParseFlagsWithCallback(helpFunc func(), callback func(*flag.FlagSet)) []string

ParseFlagsWithCallback parses flags with a custom callback for additional flags. The callback receives a FlagSet to add custom flags.

type Config

type Config struct {
	GitTimeout   int      `yaml:"git_timeout"`
	Verbosity    int      `yaml:"verbosity"`
	DefaultRoots []string `yaml:"default_roots"`
}

Config represents the git-tree configuration.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config with default values. It loads configuration in this order of precedence: 1. Environment variables (GIT_TREE_*) 2. User config file (~/.treeconfig.yml) 3. Default values

func (*Config) SaveToFile

func (c *Config) SaveToFile() error

SaveToFile saves the configuration to ~/.treeconfig.yml

type ExecResult

type ExecResult struct {
	Stdout string
	Stderr string
	Status int
}

ExecResult captures the result of a command execution.

func RunCommand

func RunCommand(command, dir string) (*ExecResult, error)

RunCommand executes a shell command in a specified directory.

type Execution

type Execution struct {
	Command    string
	Dir        string
	ExecResult *ExecResult
	Error      error
}

Execution represents a single command execution.

func (*Execution) Contains

func (e *Execution) Contains(text string) bool

Contains checks if the execution output contains the specified text.

type GitTreeWalker

type GitTreeWalker struct {
	Config       *Config
	DisplayRoots []string
	RootMap      map[string][]string
	Serial       bool
}

GitTreeWalker is used to walk a directory tree and find git repositories.

func NewGitTreeWalker

func NewGitTreeWalker(args []string, serial bool) (*GitTreeWalker, error)

NewGitTreeWalker creates a new GitTreeWalker.

func (*GitTreeWalker) AbbreviatePath

func (w *GitTreeWalker) AbbreviatePath(dir string) string

AbbreviatePath abbreviates a directory path by replacing expanded root prefixes with their original display representations. If a root was specified as an environment variable (e.g., $work), this will condense any path under that root to use the variable name (e.g., /mnt/f/work/foo -> $work/foo).

func (*GitTreeWalker) FindAndProcessRepos

func (w *GitTreeWalker) FindAndProcessRepos(callback func(dir, rootArg string))

FindAndProcessRepos finds git repos and yields them to the callback.

func (*GitTreeWalker) Process

func (w *GitTreeWalker) Process(processFunc func(dir string, threadID int, walker *GitTreeWalker))

Process processes the git repositories using the provided function.

type Logger

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

Logger provides thread-safe logging with verbosity control and color support.

func GetLogger

func GetLogger() *Logger

GetLogger returns the singleton logger instance.

func NewLogger

func NewLogger() *Logger

NewLogger creates a new Logger instance.

func (*Logger) GetVerbosity

func (l *Logger) GetVerbosity() int

GetVerbosity returns the current verbosity level.

func (*Logger) Log

func (l *Logger) Log(level int, message string, color string)

Log logs a message with the specified verbosity level and optional color.

func (*Logger) LogStdout

func (l *Logger) LogStdout(message string)

LogStdout logs a message directly to stdout (for pipes).

func (*Logger) SetVerbosity

func (l *Logger) SetVerbosity(level int)

SetVerbosity sets the verbosity level.

func (*Logger) Shutdown

func (l *Logger) Shutdown()

Shutdown gracefully shuts down the logger.

type Task

type Task struct {
	History []interface{} // Can contain *Execution or *UserMessage
}

Task remembers all commands that were executed and their results. Also remembers user output.

func NewTask

func NewTask() *Task

NewTask creates a new Task instance.

func (*Task) ExecResultExecution

func (t *Task) ExecResultExecution() *Execution

ExecResultExecution returns the most recent Execution in history.

func (*Task) MessageUser

func (t *Task) MessageUser(logLevel int, message string, color string)

MessageUser adds a user message to the history if verbosity allows.

func (*Task) MostRecentUserMessage

func (t *Task) MostRecentUserMessage() *UserMessage

MostRecentUserMessage returns the most recent UserMessage in history.

func (*Task) Perform

func (t *Task) Perform(command, dir string)

Perform executes a command and records the execution in history.

type ThreadPoolManager

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

ThreadPoolManager manages a fixed-size pool of worker goroutines.

func NewThreadPoolManager

func NewThreadPoolManager(percentAvailableProcessors float64) *ThreadPoolManager

NewThreadPoolManager creates a new thread pool manager. percentAvailableProcessors should be between 0 and 1 (e.g., 0.75 for 75%).

func (*ThreadPoolManager) AddTask

func (tp *ThreadPoolManager) AddTask(task interface{})

AddTask adds a task to the work queue.

func (*ThreadPoolManager) Shutdown

func (tp *ThreadPoolManager) Shutdown()

Shutdown signals the pool to shut down gracefully.

func (*ThreadPoolManager) Start

func (tp *ThreadPoolManager) Start(taskFunc func(task interface{}, workerID int))

Start starts the worker pool with the given task function.

func (*ThreadPoolManager) WaitForCompletion

func (tp *ThreadPoolManager) WaitForCompletion()

WaitForCompletion waits for all workers to complete.

type UserMessage

type UserMessage struct {
	Message string
	Color   string
}

UserMessage represents a message sent to the user.

type ZoweeOptimizer

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

ZoweeOptimizer optimizes environment variable definitions for git-evars.

func NewZoweeOptimizer

func NewZoweeOptimizer(initialVars map[string][]string) *ZoweeOptimizer

NewZoweeOptimizer creates a new ZoweeOptimizer.

func (*ZoweeOptimizer) Optimize

func (zo *ZoweeOptimizer) Optimize(paths []string, initialRoots []string) []string

Optimize optimizes a list of paths to generate environment variable definitions.

Jump to

Keyboard shortcuts

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