utils

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateChecksumF added in v0.0.2

func CalculateChecksumF(path models.Path) (string, error)

CalculateChecksumF calculates the checksum of a given file.

func CalculateChecksumS added in v0.0.2

func CalculateChecksumS(s string) string

CalculateChecksumS calculates the checksum of a given string.

func CloneGitRepository

func CloneGitRepository(url string, p models.Path, cloneDirName string, liveOutput func(string)) error

CloneGitRepository clones a remote git repository.

func CreatePrefixedTempFile added in v0.0.2

func CreatePrefixedTempFile(dir models.Path, prefix string) (models.Path, error)

CreatePrefixedTempFile creates a temporary file using os.CreateTemp.

func CreateTempDir

func CreateTempDir() (models.Path, error)

CreateTempDir creates a temporary directory using os.MkdirTemp.

func CreateTempFile

func CreateTempFile(dir models.Path) (models.Path, error)

CreateTempFile creates a temporary file using os.CreateTemp.

func FmtTree

func FmtTree(config FmtTreeConfig, nodes ...Node) string

FmtTree formats an array of Node to output an ordered information tree. Allows nesting of Node.

func GetGitFetchHead

func GetGitFetchHead(d models.Path) (string, string, error)

GetGitFetchHead retrieves the current HEAD of a local repository. Returns long commit hash, commit abbreviation and/or error.

func GetGitHasUnpublishedChanges

func GetGitHasUnpublishedChanges(d models.Path) (bool, error)

GetGitHasUnpublishedChanges returns whether a local repository has unpushed commits. In case of any errors, true is returned.

func GetGitHasUntrackedChanges

func GetGitHasUntrackedChanges(d models.Path) (bool, error)

GetGitHasUntrackedChanges returns whether a local repository has uncommitted changes. In case of any errors, true is returned.

func GetGitRemoteUrl

func GetGitRemoteUrl(d models.Path) (string, error)

GetGitRemoteUrl retrieves the remote url from a git directory tree.

func GetGitRootDirectory

func GetGitRootDirectory(d models.Path) (string, error)

GetGitRootDirectory retrieves the root of a git directory tree.

func GetGitVersion

func GetGitVersion() (string, error)

GetGitVersion retrieves the git version installed in the current environment. Can also be used to check if git is installed.

func GitCheckout

func GitCheckout(repository models.Path, ref string) error

GitCheckout changes a local repository's HEAD.

func GitPull added in v0.0.2

func GitPull(repository models.Path, liveOutput func(string)) error

GitPull changes a local repository's HEAD.

func MaxInt added in v0.0.2

func MaxInt(a, b int) int

func MinInt added in v0.0.2

func MinInt(a, b int) int

func ReadFileToStr

func ReadFileToStr(path models.Path) (string, error)

ReadFileToStr is a wrapper for os.ReadFile that checks for the file's existence before reading a file and returns the file's contents as a string.

func RunCommand

func RunCommand(d models.Path, command string, args ...string) (string, string, error)

RunCommand is a subset-wrapper for exec.Command, providing separate return values for stdout and stderr.

func RunCommandCombinedOutput

func RunCommandCombinedOutput(d models.Path, command string, args ...string) (string, error)

RunCommandCombinedOutput is a subset-wrapper for exec.Command, returning both stdout and stderr in one string.

func RunCommandLiveOutput added in v0.0.2

func RunCommandLiveOutput(fStdout func(string), fStderr func(string), wd models.Path, command string, args ...string) error

RunCommandLiveOutput is a wrapper for exec.Command that takes a callback function for updates in both stdout and stderr streams.

func RunCommandLiveOutputCombinedOutput added in v0.0.2

func RunCommandLiveOutputCombinedOutput(fStdout func(string), wd models.Path, command string, args ...string) error

RunCommandLiveOutputCombinedOutput is a wrapper for exec.Command that takes a callback function for updates in a combined stdout and stderr stream.

func StringInsert

func StringInsert(original string, insert string, startDelimiter string, endDelimiter string) (string, error)

StringInsert inserts a string between the start and end delimiter strings. Use StringInsertAtFirst if multiple occurrences of both delimiters are allowed in the input string.

func StringInsertAtFirst

func StringInsertAtFirst(original string, insert string, startDelimiter string, endDelimiter string) (string, error)

StringInsertAtFirst is the same as StringInsert, but allows the occurrence of multiple delimiter string in the input string by only replacing the first start-end combination.

func WriteStrToFile

func WriteStrToFile(path models.Path, str string) error

WriteStrToFile is a wrapper for os.WriteFile.

Types

type FmtTreeConfig

type FmtTreeConfig struct {
	/*
		Indent defines the indent contents for subnodes.
	*/
	Indent string

	/*
		NewLinesAtTopLevel defines if there should be any spacing between top-level nodes.
	*/
	NewLinesAtTopLevel bool
}

FmtTreeConfig is a configuration structure when formatting a Node tree.

type Node

type Node struct {
	Key   string
	Value interface{}
}

Node is a small key-value structure to fake an ordered dictionary. Should only be used for formatting with FmtTree.

Jump to

Keyboard shortcuts

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