cfg

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cfg handles working with the Glide configuration files.

The cfg package contains the ability to parse (unmarshal) and write (marshal) glide.yaml and glide.lock files. These files contains the details about projects managed by Glide.

To convert yaml into a cfg.Config instance use the cfg.ConfigFromYaml function. The yaml, typically in a glide.yaml file, has the following structure.

package: github.com/Masterminds/glide
homepage: https://masterminds.github.io/glide
license: MIT
owners:
- name: Matt Butcher
  email: technosophos@gmail.com
  homepage: http://technosophos.com
- name: Matt Farina
  email: matt@mattfarina.com
  homepage: https://www.mattfarina.com
ignore:
- appengine
excludeDirs:
- node_modules
import:
- package: gopkg.in/yaml.v2
- package: github.com/Masterminds/vcs
  version: ^1.2.0
  repo:    git@github.com:Masterminds/vcs
  vcs:     git
- package: github.com/codegangsta/cli
- package: github.com/Masterminds/semver
  version: ^1.0.0

These elements are:

  • package: The top level package is the location in the GOPATH. This is used for things such as making sure an import isn't also importing the top level package.
  • homepage: To find the place where you can find details about the package or applications. For example, http://k8s.io
  • license: The license is either an SPDX license string or the filepath to the license. This allows automation and consumers to easily identify the license.
  • owners: The owners is a list of one or more owners for the project. This can be a person or organization and is useful for things like notifying the owners of a security issue without filing a public bug.
  • ignore: A list of packages for Glide to ignore importing. These are package names to ignore rather than directories.
  • excludeDirs: A list of directories in the local codebase to exclude from scanning for dependencies.
  • import: A list of packages to import. Each package can include:
  • package: The name of the package to import and the only non-optional item.
  • version: A semantic version, semantic version range, branch, tag, or commit id to use.
  • repo: If the package name isn't the repo location or this is a private repository it can go here. The package will be checked out from the repo and put where the package name specifies. This allows using forks.
  • vcs: A VCS to use such as git, hg, bzr, or svn. This is only needed when the type cannot be detected from the name. For example, a repo ending in .git or on GitHub can be detected to be Git. For a repo on Bitbucket we can contact the API to discover the type.
  • testImport: A list of development packages not already listed under import. Each package has the same details as those listed under import.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Name is the name of the package or application.
	Name string `yaml:"package"`

	// Description is a short description for a package, application, or library.
	// This description is similar but different to a Go package description as
	// it is for marketing and presentation purposes rather than technical ones.
	Description string `json:"description,omitempty"`

	// Home is a url to a website for the package.
	Home string `yaml:"homepage,omitempty"`

	// License provides either a SPDX license or a path to a file containing
	// the license. For more information on SPDX see http://spdx.org/licenses/.
	// When more than one license an SPDX expression can be used.
	License string `yaml:"license,omitempty"`

	// Owners is an array of owners for a project. See the Owner type for
	// more detail. These can be one or more people, companies, or other
	// organizations.
	Owners Owners `yaml:"owners,omitempty"`

	// Ignore contains a list of packages to ignore fetching. This is useful
	// when walking the package tree (including packages of packages) to list
	// those to skip.
	Ignore []string `yaml:"ignore,omitempty"`

	// Exclude contains a list of directories in the local application to
	// exclude from scanning for dependencies.
	Exclude []string `yaml:"excludeDirs,omitempty"`

	// Imports contains a list of all non-development imports for a project. For
	// more detail on how these are captured see the Dependency type.
	Imports Dependencies `yaml:"import"`

	// DevImports contains the test or other development imports for a project.
	// See the Dependency type for more details on how this is recorded.
	DevImports Dependencies `yaml:"testImport,omitempty"`
}

Config is the top-level configuration object.

func ConfigFromYaml

func ConfigFromYaml(yml []byte) (*Config, error)

ConfigFromYaml returns an instance of Config from YAML

func (*Config) AddImport

func (c *Config) AddImport(deps ...*Dependency) error

AddImport appends dependencies to the import list, deduplicating as we go.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone performs a deep clone of the Config instance

func (*Config) DeDupe

func (c *Config) DeDupe() error

DeDupe consolidates duplicate dependencies on a Config instance

func (*Config) HasDependency

func (c *Config) HasDependency(name string) bool

HasDependency returns true if the given name is listed as an import or dev import.

func (*Config) HasExclude

func (c *Config) HasExclude(ex string) bool

HasExclude returns true if the given name is listed on the exclude list.

func (*Config) HasIgnore

func (c *Config) HasIgnore(name string) bool

HasIgnore returns true if the given name is listed on the ignore list.

func (*Config) Hash

func (c *Config) Hash() (string, error)

Hash generates a sha256 hash for a given Config

func (*Config) Marshal

func (c *Config) Marshal() ([]byte, error)

Marshal converts a Config instance to YAML

func (*Config) MarshalYAML

func (c *Config) MarshalYAML() (interface{}, error)

MarshalYAML is a hook for gopkg.in/yaml.v2 in the marshaling process

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a hook for gopkg.in/yaml.v2 in the unmarshalling process

func (*Config) WriteFile

func (c *Config) WriteFile(glidepath string) error

WriteFile writes a Glide YAML file.

This is a convenience function that marshals the YAML and then writes it to the given file. If the file exists, it will be clobbered.

type Dependencies

type Dependencies []*Dependency

Dependencies is a collection of Dependency

func (Dependencies) Clone

func (d Dependencies) Clone() Dependencies

Clone performs a deep clone of Dependencies

func (Dependencies) DeDupe

func (d Dependencies) DeDupe() (Dependencies, error)

DeDupe cleans up duplicates on a list of dependencies.

func (Dependencies) Get

func (d Dependencies) Get(name string) *Dependency

Get a dependency by name

func (Dependencies) Has

func (d Dependencies) Has(name string) bool

Has checks if a dependency is on a list of dependencies such as import or testImport

func (Dependencies) Remove

func (d Dependencies) Remove(name string) Dependencies

Remove removes a dependency from a list of dependencies

type Dependency

type Dependency struct {
	Name        string   `yaml:"package"`
	Reference   string   `yaml:"version,omitempty"`
	Pin         string   `yaml:"-"`
	Repository  string   `yaml:"repo,omitempty"`
	VcsType     string   `yaml:"vcs,omitempty"`
	Subpackages []string `yaml:"subpackages,omitempty"`
	Arch        []string `yaml:"arch,omitempty"`
	Os          []string `yaml:"os,omitempty"`
}

Dependency describes a package that the present package depends upon.

func DependencyFromLock

func DependencyFromLock(lock *Lock) *Dependency

DependencyFromLock converts a Lock to a Dependency

func (*Dependency) Clone

func (d *Dependency) Clone() *Dependency

Clone creates a clone of a Dependency

func (*Dependency) GetRepo

func (d *Dependency) GetRepo(dest string) (vcs.Repo, error)

GetRepo retrieves a Masterminds/vcs repo object configured for the root of the package being retrieved.

func (*Dependency) HasSubpackage

func (d *Dependency) HasSubpackage(sub string) bool

HasSubpackage returns if the subpackage is present on the dependency

func (*Dependency) MarshalYAML

func (d *Dependency) MarshalYAML() (interface{}, error)

MarshalYAML is a hook for gopkg.in/yaml.v2 in the marshaling process

func (*Dependency) Remote added in v0.12.0

func (d *Dependency) Remote() string

Remote returns the remote location to fetch source from. This location is the central place where mirrors can alter the location.

func (*Dependency) UnmarshalYAML

func (d *Dependency) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a hook for gopkg.in/yaml.v2 in the unmarshaling process

func (*Dependency) Vcs added in v0.12.0

func (d *Dependency) Vcs() string

Vcs returns the VCS type to fetch source from.

type Lock

type Lock struct {
	Name        string   `yaml:"name"`
	Version     string   `yaml:"version"`
	Repository  string   `yaml:"repo,omitempty"`
	VcsType     string   `yaml:"vcs,omitempty"`
	Subpackages []string `yaml:"subpackages,omitempty"`
	Arch        []string `yaml:"arch,omitempty"`
	Os          []string `yaml:"os,omitempty"`
}

Lock represents an individual locked dependency.

func LockFromDependency

func LockFromDependency(dep *Dependency) *Lock

LockFromDependency converts a Dependency to a Lock

func (*Lock) Clone

func (l *Lock) Clone() *Lock

Clone creates a clone of a Lock.

type Lockfile

type Lockfile struct {
	Hash       string    `yaml:"hash"`
	Updated    time.Time `yaml:"updated"`
	Imports    Locks     `yaml:"imports"`
	DevImports Locks     `yaml:"testImports"`
}

Lockfile represents a glide.lock file.

func LockfileFromMap

func LockfileFromMap(ds map[string]*Dependency, hash string) *Lockfile

LockfileFromMap takes a map of dependencies and generates a lock Lockfile instance.

func LockfileFromYaml

func LockfileFromYaml(yml []byte) (*Lockfile, error)

LockfileFromYaml returns an instance of Lockfile from YAML

func NewLockfile

func NewLockfile(ds, tds Dependencies, hash string) (*Lockfile, error)

NewLockfile is used to create an instance of Lockfile.

func ReadLockFile

func ReadLockFile(lockpath string) (*Lockfile, error)

ReadLockFile loads the contents of a glide.lock file.

func (*Lockfile) Clone

func (lf *Lockfile) Clone() *Lockfile

Clone returns a clone of Lockfile

func (*Lockfile) Fingerprint

func (lf *Lockfile) Fingerprint() ([32]byte, error)

Fingerprint returns a hash of the contents minus the date. This allows for two lockfiles to be compared irrespective of their updated times.

func (*Lockfile) Marshal

func (lf *Lockfile) Marshal() ([]byte, error)

Marshal converts a Config instance to YAML

func (*Lockfile) MarshalYAML added in v0.12.0

func (lf *Lockfile) MarshalYAML() (interface{}, error)

MarshalYAML is a hook for gopkg.in/yaml.v2. It sorts import subpackages lexicographically for reproducibility.

func (*Lockfile) WriteFile

func (lf *Lockfile) WriteFile(lockpath string) error

WriteFile writes a Glide lock file.

This is a convenience function that marshals the YAML and then writes it to the given file. If the file exists, it will be clobbered.

type Locks

type Locks []*Lock

Locks is a slice of locked dependencies.

func (Locks) Clone

func (l Locks) Clone() Locks

Clone returns a Clone of Locks.

func (Locks) Len

func (l Locks) Len() int

Len returns the length of the Locks. This is needed for sorting with the sort package.

func (Locks) Less

func (l Locks) Less(i, j int) bool

Less is needed for the sort interface. It compares two locks based on their name.

func (Locks) Swap

func (l Locks) Swap(i, j int)

Swap is needed for the sort interface. It swaps the position of two locks.

type Owner

type Owner struct {

	// Name describes the name of an organization.
	Name string `yaml:"name,omitempty"`

	// Email is an email address to reach the owner at.
	Email string `yaml:"email,omitempty"`

	// Home is a url to a website for the owner.
	Home string `yaml:"homepage,omitempty"`
}

Owner describes an owner of a package. This can be a person, company, or other organization. This is useful if someone needs to contact the owner of a package to address things like a security issue.

func (*Owner) Clone

func (o *Owner) Clone() *Owner

Clone creates a clone of a Dependency

type Owners

type Owners []*Owner

Owners is a list of owners for a project.

func (Owners) Clone

func (o Owners) Clone() Owners

Clone performs a deep clone of Owners

Jump to

Keyboard shortcuts

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