tools

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFencedCodeBlock

func AppendFencedCodeBlock(buf *bytes.Buffer, content string, languageHint string)

AppendFencedCodeBlock adds a standard Markdown fenced code block to the buffer.

func AppendFileMarkerFooter

func AppendFileMarkerFooter(buf *bytes.Buffer, filePath string)

AppendFileMarkerFooter adds the explicit file end marker.

func AppendFileMarkerHeader

func AppendFileMarkerHeader(buf *bytes.Buffer, filePath string)

AppendFileMarkerHeader adds the explicit file start marker.

func AppendSectionHeader

func AppendSectionHeader(buf *bytes.Buffer, title string)

AppendSectionHeader adds a standard Markdown H3 section header to the buffer.

func CaptureCommandOutput

func CaptureCommandOutput(cwd string, commandName string, args ...string) (stdoutStr string, stderrStr string, err error)

CaptureCommandOutput executes a command and captures its stdout and stderr. Returns stdout string, stderr string, and any error (including *exec.ExitError if command ran but exited non-zero).

func CaptureGitOutput

func CaptureGitOutput(cwd string, args ...string) (string, string, error)

CaptureGitOutput runs a git command and captures its stdout and stderr. Returns stdout string, stderr string, and any error.

func CheckGitPrereqs

func CheckGitPrereqs() (string, error)

CheckGitPrereqs verifies 'git' command exists and current directory is a Git repo.

func CommandExists

func CommandExists(name string) bool

CommandExists checks if a command executable name is found in the system's PATH.

func ExecuteCommand

func ExecuteCommand(cwd, commandName string, args ...string) error

ExecuteCommand runs an arbitrary command, piping its stdout, stderr, and stdin. It's a utility for commands where output capture isn't needed, just execution. TODO: This function pipes the command's stdio directly. Callers (e.g., commands in cmd/)

should use their ui.Presenter instance to announce the command *before* calling this function
if user-facing status information is desired.

func ExecuteGitCommand

func ExecuteGitCommand(cwd string, args ...string) error

ExecuteGitCommand runs a git command, piping stdio.

func GetCurrentBranchName

func GetCurrentBranchName(cwd string) (string, error)

GetCurrentBranchName retrieves the current Git branch name. Returns an error if in a detached HEAD state or if the branch name cannot be determined.

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo checks if a directory contains a .git subdirectory or file (for worktrees).

func IsWorkingDirClean

func IsWorkingDirClean(cwd string) (bool, error)

IsWorkingDirClean checks for staged, unstaged, or untracked files.

func LocalBranchExists

func LocalBranchExists(cwd, branchName string) (bool, error)

LocalBranchExists checks if a local branch exists by its short name.

func ReadFileContent

func ReadFileContent(filePath string) ([]byte, error)

ReadFileContent reads the entire content of the file at the specified path. Returns the content as a byte slice or an error if reading fails.

func WriteBufferToFile

func WriteBufferToFile(filePath string, buf *bytes.Buffer) error

WriteBufferToFile writes the content of a bytes.Buffer to the specified file path. It uses default file permissions (0644). It prints informational messages about writing to os.Stdout. TODO: Refactor to remove direct fmt.Printf calls.

Calling commands should use their Presenter for user-facing messages
or a Logger for debug/trace information related to file writing.
This function should focus solely on writing the file.

Types

type BranchSyncStatus added in v0.0.2

type BranchSyncStatus int

BranchSyncStatus represents the synchronization state of a local branch relative to its remote.

const (
	StatusUpToDate BranchSyncStatus = iota
	StatusAhead
	StatusBehind
	StatusDiverged
	StatusNoUpstreamOrRemoteMissing
	StatusError
)

func GetLocalBranchSyncStatus added in v0.0.2

func GetLocalBranchSyncStatus(cwd, localBranchName, remoteName, remoteBranchName string) (status BranchSyncStatus, aheadCount int, behindCount int, err error)

GetLocalBranchSyncStatus compares a local branch with its specified remote-tracking branch. Assumes 'git fetch' has been run recently enough for the remote-tracking ref to be locally available if it exists remotely.

func (BranchSyncStatus) String added in v0.0.2

func (s BranchSyncStatus) String() string

String provides a human-readable representation of BranchSyncStatus.

Jump to

Keyboard shortcuts

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