Documentation ¶
Index ¶
- func AddFencedCB(filePath string, language string) error
- func AddFile(filePath string) error
- func AnsiblePing(hostsFile string) error
- func AppendToFile(file string, text string) error
- func CSVToLines(filename string) ([][]string, error)
- func Cd(dst string) error
- func CheckRoot() error
- func ClearPCCache() error
- func CloneRepo(url string, clonePath string, auth transport.AuthMethod) (*git.Repository, error)
- func CmdExists(cmd string) bool
- func CommanderInstalled() bool
- func Commit(repo *git.Repository, msg string) error
- func Cp(src string, dst string) error
- func CreateDirectory(path string) error
- func CreateEmptyFile(name string) bool
- func CreateFile(filePath string, fileContents []byte) error
- func CreateTag(repo *git.Repository, tag string) error
- func DeleteFile(file string) error
- func DeletePushedTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
- func DeleteTag(repo *git.Repository, tag string) error
- func DownloadFile(url string, dest string) (string, error)
- func EnvVarSet(key string) error
- func ExpandHomeDir(path string) string
- func FileExists(fileLoc string) bool
- func FileToSlice(fileName string) ([]string, error)
- func FindExportedFuncsWithoutTests(pkgPath string) ([]string, error)
- func FindFile(fileName string, dirs []string) (string, error)
- func GHRelease(newVer string) error
- func GetDNSRecords(cf Cloudflare) error
- func GetFutureTime(years int, months int, days int) time.Time
- func GetHomeDir() (string, error)
- func GetOSAndArch() (string, string, error)
- func GetSSHPubKey(keyName string, password string) (*ssh.PublicKeys, error)
- func GetTags(repo *git.Repository) ([]string, error)
- func GoReleaser() error
- func Gwd() string
- func InstallBrewDeps(brewPackages []string) error
- func InstallBrewTFDeps() error
- func InstallGoDeps(deps []string) error
- func InstallGoPCDeps() error
- func InstallPCHooks() error
- func InstallVSCodeModules() error
- func IsDirEmpty(name string) (bool, error)
- func KeeperLoggedIn() bool
- func KillProcess(pid int, signal Signal) error
- func ListFilesR(path string) ([]string, error)
- func ModUpdate(recursive bool, v bool) error
- func PublicIP(protocol uint) (string, error)
- func PullRepos(dirs ...string) error
- func Push(repo *git.Repository, auth transport.AuthMethod) error
- func PushTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
- func RandomString(length int) (string, error)
- func RepoRoot() (string, error)
- func RmRf(path string) error
- func RunCommand(cmd string, args ...string) (string, error)
- func RunCommandWithTimeout(to time.Duration, command string, args ...string) (string, error)
- func RunPCHooks() error
- func SearchKeeperRecords(searchTerm string) (string, error)
- func StringInFile(path string, searchStr string) (bool, error)
- func StringInSlice(strToFind string, inputSlice []string) bool
- func StringSlicesEqual(a, b []string) bool
- func StringToInt64(value string) (int64, error)
- func StringToSlice(delimStr string, delim string) []string
- func Tidy() error
- func UpdateMageDeps(magedir string) error
- func UpdatePCHooks() error
- type Cloudflare
- type FuncInfo
- type GitConfigUserInfo
- type KeeperRecord
- type LogInfo
- type Signal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFencedCB ¶ added in v1.1.8
AddFencedCB helps to address MD040 issues found with markdownlint by adding the input language to fenced code blocks in the input filePath.
func AddFile ¶ added in v1.0.9
AddFile adds the `file` at the input `filePath` to the staging area for its associated repo.
func AnsiblePing ¶ added in v1.1.9
AnsiblePing runs ansible all -m ping against all nodes found in the input hostsFile.
Example hostsFile input: "k3s-ansible/inventory/cowdogmoo/hosts.ini"
func AppendToFile ¶ added in v1.0.3
AppendToFile appends an input text string to the end of the input file.
func CSVToLines ¶ added in v1.2.1
CSVToLines reads the contents of the specified CSV file and returns its contents as a two-dimensional string slice, where each element in the outer slice represents a row in the CSV file, and each element in the inner slice represents a value in that row. The first row in the CSV file is skipped, as it is assumed to contain column headers. If the file cannot be read or parsed, an error is returned.
func Cd ¶ added in v1.0.8
Cd is used to change the current working directory to the specified destination.
func CheckRoot ¶
func CheckRoot() error
CheckRoot will check to see if the process is being run as root
func ClearPCCache ¶ added in v1.0.3
func ClearPCCache() error
ClearPCCache Clears the pre-commit cache.
func CloneRepo ¶
func CloneRepo(url string, clonePath string, auth transport.AuthMethod) ( *git.Repository, error)
CloneRepo clones the repo specified with the input `url` to `clonePath`.
func CmdExists ¶ added in v1.1.4
CmdExists checks $PATH for for the input cmd. It returns true if the command is found, otherwise it returns false.
func CommanderInstalled ¶ added in v1.1.9
func CommanderInstalled() bool
CommanderInstalled returns true if keeper commander is installed on the current system.
func CreateDirectory ¶ added in v1.1.1
CreateDirectory creates a directory at the input path. If any part of the input path doesn't exist, create it. Return an error if the path already exists.
func CreateEmptyFile ¶
CreateEmptyFile creates an file based on the name input. It returns true if the file was created, otherwise it returns false.
func CreateFile ¶ added in v1.0.9
CreateFile creates a file at the input filePath with the specified fileContents.
func CreateTag ¶ added in v1.0.9
CreateTag is used to create an input `tag` in the specified `repo` if it doesn't already exist. Resource: https://github.com/go-git/go-git/blob/bf3471db54b0255ab5b159005069f37528a151b7/_examples/tag-create-push/main.go
func DeleteFile ¶ added in v1.0.4
DeleteFile deletes the input file
func DeletePushedTag ¶ added in v1.0.9
func DeletePushedTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
DeletePushedTag deletes an input `tag` that has been pushed to remote.
func DownloadFile ¶ added in v1.1.3
DownloadFile downloads the file at the input `url` to the specified `dest` on the local filesystem.
func EnvVarSet ¶ added in v1.1.1
EnvVarSet checks if an input environment variable is set by checking the input key for an associated value. If an env var is not set, an error is returned.
func ExpandHomeDir ¶ added in v1.3.0
ExpandHomeDir expands the tilde character in a path to the user's home directory. The function takes a string representing a path and checks if the first character is a tilde (~). If it is, the function replaces the tilde with the user's home directory. The path is returned unchanged if it does not start with a tilde or if there's an error retrieving the user's home directory.
Example usage:
pathWithTilde := "~/Documents/myfile.txt" expandedPath := ExpandHomeDir(pathWithTilde)
Parameters:
path: The string containing a path that may start with a tilde (~) character.
Returns:
string: The expanded path with the tilde replaced by the user's home directory, or the original path if it does not start with a tilde or there's an error retrieving the user's home directory.
func FileExists ¶
FileExists will return true if a file specified with fileLoc exists. If the file does not exist, it returns false.
func FileToSlice ¶
FileToSlice reads an input file into a slice, removes blank strings, and returns it.
func FindExportedFuncsWithoutTests ¶ added in v1.2.2
FindExportedFuncsWithoutTests finds all exported functions in a given package path that do not have corresponding tests. It returns a slice of function names or an error if there is a problem parsing the package or finding the tests.
func FindFile ¶ added in v1.1.2
FindFile looks for an input `filename` in the specified set of `dirs`. The filepath is returned if the `filename` is found.
func GHRelease ¶ added in v1.1.9
GHRelease creates a new release with the input newVer using the gh cli tool. Example newVer: v1.0.1
func GetDNSRecords ¶ added in v1.1.9
func GetDNSRecords(cf Cloudflare) error
GetDNSRecords retrieves the DNS records from cloudflare.
func GetFutureTime ¶ added in v1.0.7
GetFutureTime returns the date and time of the input years, months, and days parameters from the current time.
func GetHomeDir ¶
GetHomeDir returns the path to current user's home directory
func GetOSAndArch ¶ added in v1.2.5
GetOSAndArch detects the current system's OS and architecture, and returns them as strings. The function returns an error if the OS or architecture is not supported.
Example usage:
osName, archName, err := GetOSAndArch() if err != nil { fmt.Printf("Error detecting OS and architecture: %v\n", err) } else { fmt.Printf("Detected OS: %s, architecture: %s\n", osName, archName) }
Returns:
string: The detected operating system name (i.e., "linux", "darwin", or "windows"). string: The detected architecture name (i.e., "amd64", "arm64", or "armv"). error: An error if the OS or architecture is not supported or cannot be detected.
func GetSSHPubKey ¶ added in v1.0.9
func GetSSHPubKey(keyName string, password string) (*ssh.PublicKeys, error)
GetSSHPubKey returns the public SSH key for the input `keyName` and uses the input `password` (if provided) to decrypt the associated private key.
func GoReleaser ¶ added in v1.1.4
func GoReleaser() error
GoReleaser Runs goreleaser to generate all of the supported binaries specified in `.goreleaser`.
func InstallBrewDeps ¶ added in v1.2.1
InstallBrewDeps runs brew install for the input brew packages.
func InstallBrewTFDeps ¶ added in v1.2.1
func InstallBrewTFDeps() error
InstallBrewTFDeps installs dependencies for terraform projects with homebrew.
func InstallGoDeps ¶ added in v1.0.3
InstallGoDeps runs go install for the input dependencies.
func InstallGoPCDeps ¶ added in v1.0.3
func InstallGoPCDeps() error
InstallGoPCDeps Installs dependencies used for pre-commit with golang projects.
func InstallPCHooks ¶ added in v1.0.3
func InstallPCHooks() error
InstallPCHooks Installs pre-commmit hooks locally.
func InstallVSCodeModules ¶ added in v1.0.8
func InstallVSCodeModules() error
InstallVSCodeModules installs the modules used by the vscode-go extension in VSCode.
func IsDirEmpty ¶
IsDirEmpty checks if an input directory (name) is empty
func KeeperLoggedIn ¶ added in v1.1.0
func KeeperLoggedIn() bool
KeeperLoggedIn returns true if keeper vault is logged in with the input `email`. Otherwise, it returns false.
func KillProcess ¶ added in v1.2.5
KillProcess sends a signal to the process with the specified PID.
On Windows, it uses the taskkill command to terminate the process. On Unix-like systems, it sends the specified signal to the process using the syscall.Kill function.
Parameters: - pid: The process ID of the process to kill. - signal: The signal to send to the process. Currently, only SignalKill is supported, which will terminate the process.
Returns: - error: An error if the process could not be killed.
Example usage:
err := KillProcess(1234, SignalKill) if err != nil { fmt.Printf("Failed to kill process: %v", err) } else { fmt.Println("Process terminated successfully") }
Note that SignalKill may not work on all platforms. For more information, see the documentation for the syscall package.
func ListFilesR ¶ added in v1.1.7
ListFilesR lists the files found recursively from the input `path`.
func ModUpdate ¶ added in v1.1.3
ModUpdate runs `go get -u` or `go get -u ./... if `recursive` is set to true. The `v` parameter provides verbose output if set to true.
func PublicIP ¶ added in v1.0.1
PublicIP uses several external services to get the public IP address of the system running it using https://pkg.go.dev/github.com/GlenDC/go-external-ip. It returns a public IP address or an error.
func PullRepos ¶ added in v1.2.2
PullRepos updates all git repositories found in the given directories by pulling changes from the upstream branch. It looks for repositories by finding directories with a ".git" subdirectory. If a repository is not on the default branch, it will switch to the default branch before pulling changes. Returns an error if any step of the process fails.
func Push ¶ added in v1.0.9
func Push(repo *git.Repository, auth transport.AuthMethod) error
Push pushes the contents of the input `repo` to the default remote (origin).
func PushTag ¶ added in v1.0.9
func PushTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
PushTag is used to push a tag to remote.
func RandomString ¶ added in v1.0.7
RandomString returns a random string of the specified length.
func RmRf ¶ added in v1.1.1
RmRf removes an input path and everything in it. If the input path doesn't exist, an error is returned.
func RunCommand ¶
RunCommand runs a specified system command
func RunCommandWithTimeout ¶ added in v1.0.5
RunCommandWithTimeout runs a command for a specified number of seconds before timing out and returning the output.
func RunPCHooks ¶ added in v1.0.3
func RunPCHooks() error
RunPCHooks Runs all pre-commit hooks locally.
func SearchKeeperRecords ¶ added in v1.1.9
SearchKeeperRecords searches the logged-in user's keeper records for records matching the input searchTerm.
The searchTerm can be a string or regex.
Example Inputs:
SearchKeeperRecords("TESTING") SearchKeeperRecords("TEST.*RD")
If a searchTerm matches a record, the associated UID is returned.
func StringInFile ¶ added in v1.0.3
StringInFile searches for input searchStr in input the input filepath.
func StringInSlice ¶
StringInSlice determines if an input string exists in an input slice. It returns true if the string is found, otherwise it returns false.
func StringSlicesEqual ¶ added in v1.3.0
StringSlicesEqual checks if two string slices are equal.
It returns true if the slices have the same length and same values, false otherwise.
Parameters: a: the first string slice to be compared. b: the second string slice to be compared.
Returns: bool: true if the slices are equal, false otherwise.
func StringToInt64 ¶ added in v1.0.6
StringToInt64 returns the converted int64 value of an input string.
func StringToSlice ¶ added in v1.1.2
StringToSlice converts an input string (`delimStr`) using the accompanying delimiter (`delim`) to a string slice.
func UpdateMageDeps ¶ added in v1.0.8
UpdateMageDeps updates mage-specific dependencies using the input path to the associated go.mod.
func UpdatePCHooks ¶ added in v1.0.3
func UpdatePCHooks() error
UpdatePCHooks Updates pre-commit hooks locally.
Types ¶
type Cloudflare ¶ added in v1.1.9
type Cloudflare struct { CFApiKey string CFEmail string CFZoneID string Email string Endpoint string Client http.Client }
Cloudflare holds information needed to interface with the cloudflare API.
type FuncInfo ¶ added in v1.2.1
type FuncInfo struct { // FilePath is the file path of the source file containing the function declaration. FilePath string // FuncName is the name of the exported function. FuncName string }
FuncInfo contains information about an exported function, including the file path and function name.
func FindExportedFunctionsInPackage ¶ added in v1.2.1
FindExportedFunctionsInPackage finds all exported functions in a given Go package by recursively parsing all non-test Go files in the package directory and returning a slice of FuncInfo structs, each containing the file path and the name of an exported function. If no exported functions are found in the package, an error is returned.
Parameters:
pkgPath: A string representing the path to the directory containing the package to search for exported functions.
Returns:
[]FuncInfo: A slice of FuncInfo structs, each containing the file path and the name of an exported function found in the package. error: An error if no exported functions are found.
Example:
packagePath := "/path/to/your/go/package" funcs, err := FindExportedFunctionsInPackage(packagePath)
if err != nil { log.Fatalf("failed to find exported functions: %v", err) } for _, f := range funcs { log.Printf("Exported function %s found in file %s\n", f.Name, f.FilePath) }
type GitConfigUserInfo ¶ added in v1.0.9
GitConfigUserInfo holds a username and email to use for user.name and user.email.
func GetGlobalUserCfg ¶ added in v1.0.9
func GetGlobalUserCfg() (GitConfigUserInfo, error)
GetGlobalUserCfg returns the username and email from the global git user settings.
type KeeperRecord ¶ added in v1.1.9
type KeeperRecord struct { UID string Title string URL string Username string Password string TOTP string Note string }
KeeperRecord represents a record maintained by Keeper.
func RetrieveKeeperRecord ¶ added in v1.2.3
func RetrieveKeeperRecord(keeperUID string) (KeeperRecord, error)
RetrieveKeeperRecord returns the record found with the input keeperPath.
type LogInfo ¶ added in v1.0.4
LogInfo contains parameters associated with logging throughout the program.
func CreateLogFile ¶ added in v1.0.4
CreateLogFile creates logs/ in the cwd. The cwd name is used to name the log file.