utils

package
v0.13.116 Latest Latest
Warning

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

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

Documentation

Overview

Package utils provides common utilities for the gh-dxp extension.

Package utils provides common utilities for the gh-dxp extension.

Package utils provides command execution utilities for Linux systems.

revive:disable

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForMultiline added in v0.9.4

func AskForMultiline(question string) (string, error)

AskForMultiline prompts the user for a multiline input and returns the response.

func AskForString added in v0.9.4

func AskForString(question string, defaultAnswer string) (string, error)

AskForString prompts the user for a string input and returns the response.

func AskToConfirm added in v0.9.4

func AskToConfirm(question string) (bool, error)

AskToConfirm prompts the user with a yes/no question and returns their response.

func CheckFilesUpdated added in v0.9.5

func CheckFilesUpdated(changedFiles []string, patterns []string) bool

CheckFilesUpdated checks if any of the specified patterns match the changed files.

func ConvertTerminalOutputIntoList added in v0.9.4

func ConvertTerminalOutputIntoList(changedFilesString string) []string

ConvertTerminalOutputIntoList converts terminal output on multiple lines to a list of strings

func ConvertToGitRootRelativePath added in v0.13.110

func ConvertToGitRootRelativePath(exe Executor, currentPath, dir string) (string, error)

ConvertToGitRootRelativePath converts a given directory path to a path relative to the git root.

func DirectoryExists added in v0.13.6

func DirectoryExists(path string) (bool, error)

DirectoryExists checks whether a directory exists.

func FileExists added in v0.0.2

func FileExists(path string) bool

FileExists returns true if a given file exists, and false if it doesn't.

func GetChangedFiles added in v0.9.4

func GetChangedFiles(exe Executor) ([]string, error)

GetChangedFiles returns a list of changed files in the current repo

func GetGitRootDirectory added in v0.2.4

func GetGitRootDirectory(exe Executor) (string, error)

GetGitRootDirectory returns the root directory of the current git repo.

func GetTrackedChanges added in v0.7.8

func GetTrackedChanges(exe Executor) ([]string, error)

GetTrackedChanges returns a list of file names for changed files in the current repo

func GetUntrackedChanges added in v0.7.8

func GetUntrackedChanges(exe Executor) ([]string, error)

GetUntrackedChanges returns a list of file names for unchanged files in the current repo

func ListFilesInDirectory added in v0.2.4

func ListFilesInDirectory(exe Executor, directory string) ([]string, error)

ListFilesInDirectory returns a list of files in a given directory.

func RemoveFinalMsg added in v0.12.7

func RemoveFinalMsg(s *spinner.Spinner)

RemoveFinalMsg removes the finalmsg from a spinner. This is intended to be used if an error occurs to prevent conflicting terminal output

func SetWorkDirToGitHubRoot added in v0.6.2

func SetWorkDirToGitHubRoot(exe Executor) error

SetWorkDirToGitHubRoot checks whether the current working directory is in a GitHub repo. If false, an error is raised. If true, the working directory is set to the root of that repo.

func StartSpinner

func StartSpinner(msg string, finalMsg string) *spinner.Spinner

StartSpinner starts a spinner with a message and then replaces it with a done message * when the spinner is stopped.

Types

type Executor

type Executor interface {
	Command(name string, args ...string) (string, error)
	CommandContext(ctx context.Context, name string, arg ...string) error
	GH(args ...string) (string, error)
	Chdir(dir string) error
}

Executor is an interface for running commands.

type LinuxExecutorImpl

type LinuxExecutorImpl struct {
	ExecCommand func(name string, args ...string) *exec.Cmd
}

LinuxExecutorImpl is the type of the Executor interface for Linux systems.

func LinuxExecutor

func LinuxExecutor() *LinuxExecutorImpl

LinuxExecutor returns a new LinuxExecutorImpl.

func (*LinuxExecutorImpl) Chdir added in v0.9.4

func (e *LinuxExecutorImpl) Chdir(dir string) error

Chdir changes the current working directory.

func (*LinuxExecutorImpl) Command

func (e *LinuxExecutorImpl) Command(name string, args ...string) (string, error)

Command runs an OS command and returns its output.

func (*LinuxExecutorImpl) CommandContext

func (e *LinuxExecutorImpl) CommandContext(ctx context.Context, name string, args ...string) error

CommandContext runs an OS command with a context and returns an error. The output is printed to stdout and stderr.

func (*LinuxExecutorImpl) GH

func (e *LinuxExecutorImpl) GH(args ...string) (string, error)

GH runs a GitHub CLI command and returns its output.

type NotAGitHubRepoError added in v0.4.2

type NotAGitHubRepoError struct {
	Msg string
}

NotAGitHubRepoError signifies that the current working directory is not a GitHub repo.

func (*NotAGitHubRepoError) Error added in v0.4.2

func (e *NotAGitHubRepoError) Error() string

Signifies that the current working directory is not a GitHub repo.

Jump to

Keyboard shortcuts

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