cmd

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2015 License: MIT Imports: 9 Imported by: 68

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 NewContext

func NewContext(projectroot string, options ...func(*gb.Context) error) (*gb.Context, error)

NewContext creates a gb.Context for the project root.

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.

Types

type Command

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

	// UsageLine demonstrates how to use this command
	UsageLine string

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

	// Description of this command
	Long 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 alternative 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.

func (*Command) Hidden

func (c *Command) Hidden() bool

Hidden indicates this is a command which is hidden from help / alldoc.go.

func (*Command) Runnable

func (c *Command) Runnable() bool

Runnable indicates this is a command that can be involved. Non runnable commands are only informational.

type Context

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

Directories

Path Synopsis
gb, a project based build tool for the Go programming language.
gb, a project based build tool for the Go programming language.
gb-vendor, a gb plugin to manage your vendored dependencies.
gb-vendor, a gb plugin to manage your vendored dependencies.

Jump to

Keyboard shortcuts

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