gomod

package
v0.0.0-...-380e484 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterModuleFiles

func FilterModuleFiles(module *ModuleTreeNode, files []string) ([]string, error)

FilterModuleFiles will return a list of files that apply to this specific module. Any file that is not relevant to this module will be excluded from the returned list. List will be empty if there are no relevant files.

func GetModulePath

func GetModulePath(file *modfile.File) (string, error)

GetModulePath retrieves the module path from the provide file description.

func IsGoMod

func IsGoMod(name string) bool

IsGoMod returns whether a given file name is `go.mod`.

func IsGoModPresent

func IsGoModPresent(path string) (bool, error)

IsGoModPresent returns whether there is a go.mod file located in the provided directory path

func IsGoSource

func IsGoSource(name string) bool

IsGoSource returns whether a given file name is a Go source code file ending in `.go`

func IsModuleChanged

func IsModuleChanged(module *ModuleTreeNode, changes []string) (bool, error)

IsModuleChanged returns whether the given set of changes applies to the module directly, and not any of its sub modules.

func LoadModuleFile

func LoadModuleFile(path string, fix modfile.VersionFixer, lax bool) (*modfile.File, error)

LoadModuleFile loads the Go module file located at the provided directory path.

func ReadModule

func ReadModule(path string, f io.Reader, fix modfile.VersionFixer, lax bool) (parse *modfile.File, err error)

ReadModule parses the module file bytes from the provided reader.

func UpdateRequires

func UpdateRequires(repoRootPath string, tags git.ModuleTags, dependencies map[string]string, force bool) error

UpdateRequires updates all modules discovered starting at repoRootPath using the provided tags and dependencies. Using force will update the module required versions regardless whether the target version less the currently written version.

func WriteModuleFile

func WriteModuleFile(path string, file *modfile.File) (err error)

WriteModuleFile writes the Go module description to the provided directory path.

Types

type Discoverer

type Discoverer struct {
	// contains filtered or unexported fields
}

Discoverer is used for discovering all modules and submodules at the provided path.

func NewDiscoverer

func NewDiscoverer(path string) *Discoverer

NewDiscoverer constructs a new Discover for the given path.

func (*Discoverer) Discover

func (d *Discoverer) Discover() error

Discover will find all modules starting from the path provided when constructing the Discoverer. Does not iterate into testdata folders.

Any previous modules discovered by Discovery will be reset.

func (*Discoverer) Modules

func (d *Discoverer) Modules() *ModuleTree

Modules returns the modules discovered after executing Discover.

func (*Discoverer) Root

func (d *Discoverer) Root() string

Root returns the root path of the module discovery.

type ModuleTree

type ModuleTree struct {
	// contains filtered or unexported fields
}

ModuleTree provides a tree for organizing Go modules with a path tree structure.

func NewModuleTree

func NewModuleTree(optFns ...func(o *ModuleTreeOptions)) *ModuleTree

NewModuleTree returns a initialized tree container for modules.

List of sub modules must be and sorted ascending list of unique paths.

func (*ModuleTree) Get

func (t *ModuleTree) Get(path string) *ModuleTreeNode

Get returns if the tree contains a module with the relative path.

If no tree root is specified, path will search for exact path the node was created with.

func (*ModuleTree) Insert

func (t *ModuleTree) Insert(modulePath string, attributes ...string) (newNode *ModuleTreeNode, err error)

Insert adds a new module to the tree. Nesting the new module within the parent modules if any.

func (*ModuleTree) InsertRel

func (t *ModuleTree) InsertRel(relModulePath string, attributes ...string) (*ModuleTreeNode, error)

func (*ModuleTree) Iterator

func (t *ModuleTree) Iterator() *ModuleTreeIterator

Iterator returns an iterator for walking the tree.

func (*ModuleTree) List

func (t *ModuleTree) List() (list []*ModuleTreeNode)

List returns a list of all nodes in the tree in sorted order.

func (*ModuleTree) ListPaths

func (t *ModuleTree) ListPaths() (list []string)

ListPaths returns a list of all node paths in the tree in sorted order.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTree) Search

func (t *ModuleTree) Search(path string) *ModuleTreeNode

Search returns the nearest module ancestor for the path.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

type ModuleTreeIterator

type ModuleTreeIterator struct {
	// contains filtered or unexported fields
}

ModuleTreeIterator provides an iterator for walking the module nodes in the tree.

func (*ModuleTreeIterator) Next

func (it *ModuleTreeIterator) Next() *ModuleTreeNode

Next returns the next node in the tree. If there are no more nodes, nil will be returned.

type ModuleTreeNode

type ModuleTreeNode struct {
	// contains filtered or unexported fields
}

ModuleTreeNode provides the module node of a ModuleTree.

func (*ModuleTreeNode) AbsPath

func (n *ModuleTreeNode) AbsPath() string

AbsPath returns the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) AncestorOf

func (n *ModuleTreeNode) AncestorOf(path string) bool

AncestorOf returns true if this module is an ancestor of the path. Not matching paths that are siblings of the module with common name prefix.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) Attributes

func (n *ModuleTreeNode) Attributes() []string

Attributes returns a list of the attributes associated with this node.

func (*ModuleTreeNode) Get

func (n *ModuleTreeNode) Get(path string) *ModuleTreeNode

Get returns the module that is the closet ancestor of the path. Returns nil if the module does not exist exactly.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) HasAttribute

func (n *ModuleTreeNode) HasAttribute(attribute string) bool

HasAttribute returns if the node has the attribute requested.

func (*ModuleTreeNode) Iterator

func (n *ModuleTreeNode) Iterator() *ModuleTreeIterator

Iterator returns an depth first iterator for the tree starting with this node as the root of the tree.

func (*ModuleTreeNode) List

func (n *ModuleTreeNode) List() (list []*ModuleTreeNode)

List returns a depth first list of all modules starting at this node.

func (*ModuleTreeNode) ListPaths

func (n *ModuleTreeNode) ListPaths() (list []string)

ListPaths returns a list of all module paths under this node.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) ParentOf

func (n *ModuleTreeNode) ParentOf(path string) bool

ParentOf returns true if this module is a direct parent of the path specified, and no other sub module is also an ancestor of it. If the path is a sub module of this module, ParentOf will return false. Use Search to find sub modules.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) Path

func (n *ModuleTreeNode) Path() string

Path returns the module path.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

func (*ModuleTreeNode) Search

func (n *ModuleTreeNode) Search(path string) *ModuleTreeNode

Search returns the module that is the closet ancestor of the path. Returns nil if no ancestor found.

Uses relative path of module from the tree's root. If the tree does not have a root specified the value will be the absolute path of the module when it was inserted into the tree.

type ModuleTreeOptions

type ModuleTreeOptions struct {
	// Sets the root directory path that all modules must be nested within. Any
	// module attempted to be inserted into the tree that is outside of this
	// root path will cause Insert to return an error.
	//
	// If set, ModuleTreeNode.PathRel will return the relative path of the
	// module from this root path.
	RootPath string
}

ModuleTreeOption provides the options for the ModuleTree's behavior.

Jump to

Keyboard shortcuts

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