cmd

package
v0.0.0-...-d160452 Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package command holds support functions and types for writing gb and gb plugins

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindProjectroot

func FindProjectroot(path string) (string, error)

FindProjectroot works upwards from path seaching for the src/ directory which identifies the project root.

func ImportPaths

func ImportPaths(ctx Context, cwd string, args []string) []string

importPaths returns the import paths to use for the given command line.

func MergeEnv

func MergeEnv(env []string, args map[string]string) []string

MergeEnv merges args into env, overwriting entries.

func MustGetwd

func MustGetwd() string

func RelImportPaths

func RelImportPaths(ctx *gb.Context, paths ...string) []string

RelImportPaths converts a list of potentially relative import path (a path starting with .) to an absolute import path relative to the project root of the Context provided.

func ResolvePackages

func ResolvePackages(r Resolver, paths ...string) ([]*gb.Package, error)

ResolvePackages resolves import paths to packages.

func ResolvePackagesWithTests

func ResolvePackagesWithTests(r Resolver, paths ...string) ([]*gb.Package, error)

ResolvePackagesWithTests is similar to ResolvePackages however it also loads the test and external test packages of args into the context.

func RunCommand

func RunCommand(fs *flag.FlagSet, cmd *Command, projectroot, goroot string, args []string) error

RunCommand detects the project root, parses flags and runs the Command.

func Test

func Test(flags []string, pkgs ...*gb.Package) error

Test returns a Target representing the result of compiling the package pkg, and its dependencies, and linking it with the test runner.

func TestFlags

func TestFlags(testArgs []string) []string

TestFlags appends "-test." for flags that are passed to the test binary.

func TestFlagsExtraParse

func TestFlagsExtraParse(args []string) (parseArgs []string, extraArgs []string, err error)

TestFlagsExtraParse is used to separate known arguments from unknown arguments passed on the command line. Returns a string slice of test plugin arguments (parseArgs), and a slice of string arguments for the test binary (extraArgs). An error is returned if an argument is used twice, or an argument value is incorrect.

Types

type Command

type Command struct {
	// Name of the command
	Name string

	// Single line description of the purpose of the command
	ShortDesc string

	// Run is invoked with a Context derived from the Project and arguments
	// left over after flag parsing.
	Run func(ctx *gb.Context, args []string) error

	// AddFlags installs additional flags to be parsed before Run.
	AddFlags func(fs *flag.FlagSet)

	// Allow plugins to modify arguments
	FlagParse func(fs *flag.FlagSet, args []string) error

	// ParseArgs provides an alterntive method to parse arguments.
	// By default, arguments will be parsed as import paths with
	// ImportPaths
	ParseArgs func(ctx *gb.Context, cwd string, args []string) []string
}

Command represents a subcommand, or plugin that is executed within a gb project.

type Context

type Context interface {
	Srcdirs() []string
	AllPackages(string) []string
}

type CoverVar

type CoverVar struct {
	File string // local file name
	Var  string // name of count struct
}

CoverVar holds the name of the generated coverage variables targeting the named file.

type Resolver

type Resolver interface {
	// Srcdirs returns []string{ "$PROJECT/src", "$PROJECT/vendor/src" }
	Srcdirs() []string

	// ResolvePackage resolves the import path to a *gb.Package
	ResolvePackage(path string) (*gb.Package, error)

	// ResolvePackagesWithTests is similar to ResolvePackages however
	// it also loads the test and external test packages of args into
	// the context.
	ResolvePackageWithTests(path string) (*gb.Package, error)
}

Resolver resolves packages.

Directories

Path Synopsis
gb-list lists the packages named by the import paths, one per line.
gb-list lists the packages named by the import paths, one per line.

Jump to

Keyboard shortcuts

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