context

package
v0.0.0-...-7d7bdd9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2015 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package context gathers the status of packages and stores it in Context. A new Context needs to be pointed to the root of the project and any project owned vendor file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingGOROOT returns if the GOROOT was not found.
	ErrMissingGOROOT = errors.New("Unable to determine GOROOT.")
	// ErrMissingGOPATH returns if no GOPATH was found.
	ErrMissingGOPATH = errors.New("Missing GOPATH. Check your environment variable GOPATH.")
)

Functions

func CopyPackage

func CopyPackage(destPath, srcPath string, ignoreFiles []string) error

CopyPackage copies the files from the srcPath to the destPath, destPath folder and parents are are created if they don't already exist.

func RemovePackage

func RemovePackage(path, root string) error

RemovePackage removes the specified folder files. If folder is empty when done (no nested folders, remove the folder and any empty parent folders.

Types

type Conflict

type Conflict struct {
	Canonical string
	Local     string
	Operation []*Operation
	OpIndex   int
	Resolved  bool
}

Conflict reports packages that are scheduled to conflict.

func ResolveAutoLongestPath

func ResolveAutoLongestPath(cc []*Conflict) []*Conflict

ResolveAutoLongestPath finds the longest local path in each conflict and set it to be used.

func ResolveAutoShortestPath

func ResolveAutoShortestPath(cc []*Conflict) []*Conflict

ResolveAutoShortestPath finds the shortest local path in each conflict and set it to be used.

type Context

type Context struct {
	GopathList []string // List of GOPATHs in environment.
	Goroot     string   // The path to the standard library.

	RootDir        string // Full path to the project root.
	RootGopath     string // The GOPATH the project is in.
	RootImportPath string // The import path to the project.

	VendorFile         *vendorfile.File
	VendorFilePath     string // File path to vendor file.
	VendorFolder       string // Store vendor packages in this folder.
	VendorFileToFolder string // The relative path from the vendor file to the vendor folder.
	RootToVendorFile   string // The relative path from the project root to the vendor file directory.

	VendorDiscoverFolder string // Normally auto-set to "vendor"

	// Package is a map where the import path is the key.
	// Populated with LoadPackage.
	Package map[string]*Package

	// MoveRule provides the translation from origional import path to new import path.
	RewriteRule map[string]string // map[from]to

	Operation []*Operation
	// contains filtered or unexported fields
}

Context represents the current project context.

func NewContext

func NewContext(root, vendorFilePathRel, vendorFolder string, rewriteImports bool) (*Context, error)

NewContext creates new context from a given root folder and vendor file path. The vendorFolder is where vendor packages should be placed.

func NewContextWD

func NewContextWD(wdIsRoot bool) (*Context, error)

NewContextWD creates a new context. It looks for a root folder by finding a vendor file.

func (*Context) Alter

func (ctx *Context) Alter() error

Alter runs any requested package alterations.

func (*Context) Check

func (ctx *Context) Check() []*Conflict

Check returns any conflicts when more then one package can be moved into the same path.

func (*Context) IgnoreBuild

func (ctx *Context) IgnoreBuild(ignore string)

IgnoreBuild takes a space separated list of tags to ignore. "a b c" will ignore "a" OR "b" OR "c".

func (*Context) ModifyImport

func (ctx *Context) ModifyImport(sourcePath string, mod Modify) error

AddImport adds the package to the context. The vendorFolder is where the package should be added to relative to the project root.

func (*Context) ResloveApply

func (ctx *Context) ResloveApply(cc []*Conflict)

ResolveApply applies the conflict resolution selected. It chooses the Operation listed in the OpIndex field.

func (*Context) ResolveAutoVendorFileOrigin

func (ctx *Context) ResolveAutoVendorFileOrigin(cc []*Conflict) []*Conflict

ResolveAutoVendorFileOrigin resolves conflicts based on the vendor file if possible.

func (*Context) Status

func (ctx *Context) Status() ([]StatusItem, error)

Status obtains the current package status list.

func (*Context) VendorFilePackageLocal

func (ctx *Context) VendorFilePackageLocal(local string) *vendorfile.Package

VendorFilePackageLocal finds a given vendor file package give the local import path.

func (*Context) VendorFilePackagePath

func (ctx *Context) VendorFilePackagePath(canonical string) *vendorfile.Package

VendorFilePackageCanonical finds a given vendor file package give the canonical import path.

func (*Context) WriteVendorFile

func (ctx *Context) WriteVendorFile() (err error)

WriteVendorFile writes the current vendor file to the context location.

type ErrDirtyPackage

type ErrDirtyPackage struct {
	ImportPath string
}

ErrDirtyPackage returns if package is in dirty version control.

func (ErrDirtyPackage) Error

func (err ErrDirtyPackage) Error() string

type ErrMissingVendorFile

type ErrMissingVendorFile struct {
	Path string
}

ErrMissingVendorFile returns if package already exists.

func (ErrMissingVendorFile) Error

func (err ErrMissingVendorFile) Error() string

type ErrNotInGOPATH

type ErrNotInGOPATH struct {
	Missing string
}

ErrNotInGOPATH returns if not currently in the GOPATH.

func (ErrNotInGOPATH) Error

func (err ErrNotInGOPATH) Error() string

type ErrOldVersion

type ErrOldVersion struct {
	Message string
}

ErrOldVersion returns if vendor file is not in the vendor folder.

func (ErrOldVersion) Error

func (err ErrOldVersion) Error() string

type ErrPackageExists

type ErrPackageExists struct {
	Package string
}

ErrPackageExists returns if package already exists.

func (ErrPackageExists) Error

func (err ErrPackageExists) Error() string

type File

type File struct {
	Package *Package
	Path    string
	Imports []string

	ImportComment string
}

File holds a reference to the imports in a file and the file locaiton.

type Modify

type Modify byte

Modify is the type of modifcation to do.

const (
	AddUpdate Modify = iota // Add or update the import.
	Add                     // Only add, error if it already exists.
	Update                  // Only update, error if it doesn't currently exist.
	Remove                  // Remove from vendor path.
)

type Operation

type Operation struct {
	Pkg *Package

	// Source file path to move packages from.
	// Must not be empty.
	Src string

	// Destination file path to move package to.
	// If Dest if empty the package is removed.
	Dest string

	// Files to ignore for operation.
	IgnoreFile []string

	State OperationState
}

Operation defines how packages should be moved.

type OperationState

type OperationState byte

OperationState is the state of the given package move operation.

const (
	OpReady  OperationState = iota // Operation is ready to go.
	OpIgnore                       // Operation should be ignored.
	OpDone                         // Operation has been completed.
)

type Package

type Package struct {
	OriginDir  string
	Dir        string
	Canonical  string
	Local      string
	SourcePath string
	Gopath     string
	Files      []*File
	Status     Status
	// contains filtered or unexported fields
}

Package maintains information pertaining to a package.

type Status

type Status byte

Status indicates the status of the import.

const (
	// StatusUnknown indicates the status was unable to be obtained.
	StatusUnknown Status = iota
	// StatusMissing indicates import not found in GOROOT or GOPATH.
	StatusMissing
	// StatusStd indicates import found in GOROOT.
	StatusStandard
	// StatusLocal indicates import is part of the local project.
	StatusLocal
	// StatusExternal indicates import is found in GOPATH and not copied.
	StatusExternal
	// StatusUnused indicates import has been copied, but is no longer used.
	StatusUnused
	// StatusProgram indicates the import is a main package but internal or vendor.
	StatusProgram
	// StatusVendor indicates theimport is in the vendor folder.
	StatusVendor
)

func (Status) String

func (ls Status) String() string

type StatusItem

type StatusItem struct {
	Status     Status
	Canonical  string
	Local      string
	ImportedBy []string
}

ListItem represents a package in the current project.

func (StatusItem) String

func (li StatusItem) String() string

Jump to

Keyboard shortcuts

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