utils

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GitCommand = func(args ...string) (*exec.Cmd, error) {
	gitExe, err := safeexec.LookPath("git")
	if err != nil {
		programName := "git"
		if runtime.GOOS == "windows" {
			programName = "Git for Windows"
		}
		return nil, fmt.Errorf("unable to find git executable in PATH; please install %s before retrying", programName)
	}
	return exec.Command(gitExe, args...), nil
}
View Source
var IsTerminal = func(f *os.File) bool {
	return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}
View Source
var TerminalSize = func(w interface{}) (int, int, error) {
	if f, isFile := w.(*os.File); isFile {
		return terminal.GetSize(int(f.Fd()))
	}

	return 0, 0, fmt.Errorf("%v is not a file", w)
}

Functions

func DownloadFile

func DownloadFile(filepath string, url string) error

DownloadFile will download a url to a local file. It's efficient because it will write as it downloads and not load the whole file into memory.

func DownloadURL added in v0.6.0

func DownloadURL(url string) ([]byte, error)

DownloadURL downloads from a given URL and returns the response body

func ExtractOwnerRepoFromGitURL added in v0.4.0

func ExtractOwnerRepoFromGitURL(url string) (owner string, repo string, err error)

ExtractOwnerRepoFromGitURL extracts owner and repo from a Git URL: https or ssh url

func GitDir added in v0.4.0

func GitDir() (string, error)

GitDir returns the directory path of the current repository

func GitRemoteOriginURL added in v0.4.0

func GitRemoteOriginURL() (string, error)

func IfThenElse

func IfThenElse(condition bool, a interface{}, b interface{}) interface{}

IfThenElse evaluates a condition, if true returns the first parameter otherwise the second

func IsCygwinTerminal added in v0.4.0

func IsCygwinTerminal(f *os.File) bool

func IsGitRepo added in v0.4.0

func IsGitRepo() bool

IsGitRepo indicates whether the current working directory is a git repository

func NestedMapLookup

func NestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{}, err error)

NestedMapLookup ... m: a map from strings to other maps or values, of arbitrary depth ks: successive keys to reach an internal or leaf node (variadic) If an internal node is reached, will return the internal map

Returns: (Exactly one of these will be nil) rval: the target node (if found) err: an error created by fmt.Errorf

https://gist.github.com/ChristopherThorpe/fd3720efe2ba83c929bf4105719ee967 Licensed under the CC by 4.0 https://creativecommons.org/licenses/by/4.0/

func OpenInBrowser added in v0.3.0

func OpenInBrowser(url string) error

OpenInBrowser opens the url in a web browser based on OS

func RandomString added in v0.3.0

func RandomString(length int) (string, error)

RandomString generates a random string of a given length

func StringInArray

func StringInArray(str string, list []string) bool

StringInArray indicates whether a string value is contained in an array or slice

func SumFloat64 added in v0.11.0

func SumFloat64(array []float64) float64

SumFloat64 returns the sum of all float64 values of the slice

func SumInt added in v0.11.0

func SumInt(array []int) int

SumInt returns the sum of all int values of the slice

func ToplevelDir added in v0.4.0

func ToplevelDir() (string, error)

ToplevelDir returns the top-level directory path of the current repository

func TruncateString added in v0.6.0

func TruncateString(s string, num int) string

TruncateString truncates the given string to the num provided and adds an ellipsis (...).

Types

type GitRemoteURL added in v0.4.0

type GitRemoteURL struct {
	Proto string // https , ssh , git
	User  string // optional
	Host  string // host or host:port
	Path  string // full path to the repo (without .git ext)
	// contains filtered or unexported fields
}

func ParseGitRemoteOriginURL added in v0.4.0

func ParseGitRemoteOriginURL(url string) (*GitRemoteURL, error)

ParseGitRemoteOriginURL parses a git remote origin url into a struct that can be uniquely identified regardless the used protocol

func (*GitRemoteURL) Hash added in v0.4.0

func (grURL *GitRemoteURL) Hash() string

Hash computes the hash for a git remote URL only on non changing fields: different protocol or user can still refer to the same remote origin

func (*GitRemoteURL) String added in v0.4.0

func (grURL *GitRemoteURL) String() string

String returns the original raw URL of the git remote

Jump to

Keyboard shortcuts

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