cove

package module
v0.0.0-...-3970965 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: BSD-3-Clause Imports: 9 Imported by: 2

README

Cove - Libraries & CLI's that wrap the go command.

Deprecated - you should move to different solutions to these problems.

This is a small set of wrapper libraries and cli's that wrap around the golang go command.

Runtime dependencies

Unlike most go projects this one does have a dependency on the go development environment. It will not work with just the runtime.

gosh - Get Over SsH - simple script for getting go packages at supplied uri's.

Deprecated - you should prefer either vendoring your dependencies explicitly in your repo or using one of the many golang dependency management tools. We like dep for older versions of go and reluctantly use go mod for modern versions.

Note that gosh has issues being built with go1.8 and above.

Explicit ssh urls

Gosh works by taking a package/git ssh url pair, seperated by a ','.

gosh github.com/MediaMath/cove,git@github.com:MediaMath/cove.git github.com/MediaMath/foo/bar,git@github.com:MediaMath/foo.git
Implied github ssh urls.

If you do not provide a second argument with a ',' to gosh it will attempt to imply a github url.

#will use git@github.com:MediaMath/cove.git and git@github.com:MediaMath/foo.git
gosh github.com/MediaMath/cove github.com/MediaMath/foo/bar
To Install gosh
go install github.com/MediaMath/cove/gosh

cvr - wrapper around go code coverage.

The go code coverage facility is one of the few that does not respond well to path traversals. This tool provides an ability to:

  • Open go coverage reports in a web browser from the command line in 1 command.
  • Generate go coverage reports for multiple projects that match query paths in 1 go.

Run in a go project directory, this will generate and open the go coverage html report in the configured web browser:

cvr

Run in any directory, this will create a list of html coverage reports in the specified output directory.

cvr -o=path/to/some/dir github.com/MediaMath/... 
To Install cvr
go install github.com/MediaMath/cove/cvr

Documentation

Overview

Package cove is a thin wrapper around the go toolchain

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoverageProfile

func CoverageProfile(short bool, mode string, outdir string, pack Package) (string, error)

CoverageProfile creates a cover profile file for the provided package The file is created in outdir. The parameter short sets whether to run all tests or only the short ones. The mode specifies which style of cover mode is used. If a profile is able to be created its file name is returned.

Example
testdir, temperr := ioutil.TempDir("", "coverage-profile")

if temperr != nil {
	fmt.Printf("%v", temperr)
}

defer os.RemoveAll(testdir)

profile, profileErr := CoverageProfile(false, "count", testdir, "text/scanner")
if profileErr != nil {
	fmt.Printf("%v", profileErr)
}

fmt.Println(filepath.Base(profile))
Output:

text.scanner.out
Example (Short)
testdir, _ := ioutil.TempDir("", "coverage-profile")
defer os.RemoveAll(testdir)

profile, _ := CoverageProfile(true, "set", testdir, "text/scanner")
fmt.Println(filepath.Base(profile))
Output:

text.scanner.out

func CoverageReport

func CoverageReport(profile string, outdir string) (string, error)

CoverageReport turns the profile into a report using 'go tool cover'

func Get

func Get(pack Package) error

Get runs 'go get pack'

Example
if err := Get("text/scanner"); err != nil {
	fmt.Println(err)
}

if err := Get("not/a/package"); err != nil {
	fmt.Println("Got error")
}
Output:

Got error

func GetFirstGoPath

func GetFirstGoPath() string

The Go PATH variable can be a ":" separated list. The default behavior for "most" go tools when needing a canonical go path location is to just use the first one in the list. this function returns that.

func GoCmd

func GoCmd(sub string, args ...string) *exec.Cmd

GoCmd takes the sub and args and prepares a command like 'go sub arg1 arg2...'

func PackageExists

func PackageExists(pack Package) bool

PackageExists checks to see if a given package name exists

Example
if PackageExists("os/exec") {
	fmt.Println("os/exec exists")
}

if !PackageExists("boogey/woogey/bugleboy") {
	fmt.Println("boogey/woogey/bugleboy does not exist")
}
Output:

os/exec exists
boogey/woogey/bugleboy does not exist

func PackageJSON

func PackageJSON(pack Package, v interface{}) error

PackageJSON takes a SINGLE fully qualified package import path and decodes the 'go list -json' response. See $GOROOT/src/cmd/go/list.go for documentation on the json output.

Example
var info struct {
	ImportPath string
	Name       string
	Incomplete bool
}

PackageJSON("os/exec", &info)

fmt.Printf("%s %s %v", info.ImportPath, info.Name, info.Incomplete)
Output:

os/exec exec false
Example (Unknown)
var info struct {
	ImportPath string
	Name       string
	Incomplete bool
}

if err := PackageJSON("moo/boo", &info); err != nil {
	fmt.Printf("%v", err)
}
Output:

Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF
Example (Wildcard)
type JSONresponse struct {
	ImportPath string
	Name       string
	Incomplete bool
}

var resp []JSONresponse
if err := PackageJSON("os/...", &resp); err != nil {
	fmt.Printf("'go list -json os/...' returns an invalid json in the multiple return case.")
}
Output:

'go list -json os/...' returns an invalid json in the multiple return case.

func PackagePatternsAsStrings

func PackagePatternsAsStrings(paths []PackagePattern) []string

PackagePatternsAsStrings takes a slice of paths and returns a slice of strings

func PackagesAsStrings

func PackagesAsStrings(packs []Package) []string

PackagesAsStrings takes a slice of packages and returns a slice of strings

Types

type Package

type Package string

Package is a specific and unique go package

func MissingDependencies

func MissingDependencies(pack Package) ([]Package, error)

MissingDependencies returns any go packages that are missing for a given package.

Example (Unknown)
_, err := MissingDependencies("moo/boo")
if err != nil {
	fmt.Printf("%v", err)
}
Output:

Could not determine missing dependencies for moo/boo: Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF

func Packages

func Packages(paths ...PackagePattern) ([]Package, error)

Packages gets all packages that match any of the paths. The package list will only contain 1 entry per package in sorted order. Invalid paths will generate an error, but will not stop the evaluation of the other paths.

Example (Multiples)
packs, _ := Packages("text/...", "os/exec")

for _, pack := range packs {
	fmt.Println(pack)
}
Output:

os/exec
text/scanner
text/tabwriter
text/template
text/template/parse
Example (Relative)
//duplicates are filtered
packs, _ := Packages(".")

for _, pack := range packs {
	fmt.Println(pack)
}
Output:

github.com/MediaMath/cove
Example (Single)
packs, _ := Packages("text/template")

for _, pack := range packs {
	fmt.Println(pack)
}
Output:

text/template
Example (Unknown)
packs, err := Packages("foo/manchu", "text/...", "moo/...")

for _, pack := range packs {
	fmt.Println(pack)
}

if err != nil {
	fmt.Println("Had errors.")
}
Output:

text/scanner
text/tabwriter
text/template
text/template/parse
Had errors.
Example (Unknown2)
packs, err := Packages("foo/manchu")

for _, pack := range packs {
	fmt.Println(pack)
}

if err != nil {
	fmt.Println("Had errors.")
}
Output:

Had errors.
Example (Wildcard)
packs, _ := Packages("text/...")

for _, pack := range packs {
	fmt.Println(pack)
}
Output:

text/scanner
text/tabwriter
text/template
text/template/parse

func PackagesFromStrings

func PackagesFromStrings(str []string) []Package

PackagesFromStrings creates a slice of packages from a slice of strings

type PackagePattern

type PackagePattern string

PackagePattern is a pattern, potentially with wildcards, to search for packages in. It can correlate to 0 to many Packages

func PackagePatternsFromStrings

func PackagePatternsFromStrings(str []string) []PackagePattern

PackagePatternsFromStrings creates a slice of paths from a slice of strings

Directories

Path Synopsis
Package cmd provides helper functions for working with the os/exec library.
Package cmd provides helper functions for working with the os/exec library.

Jump to

Keyboard shortcuts

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